@scaleleap/logger
v1.9.13
Published
A universal logger for Scale Leap applications based on Pino.
Downloads
80
Readme
📦 @scaleleap/logger
A universal logger for Scale Leap applications based on Pino.
Download & Installation
npm i -s @scaleleap/logger
Usage
createLogger(options?: LoggerOptions)
The createLogger
function returns a pre-configured Pino instance. Optional parameters can be
passed to amend default configuration.
Example:
import { createLogger } from '@scaleleap/logger'
const log = createLogger()
log.info('Hello world')
createTestLogger(options?: LoggerOptions)
Creates a logger suitable for tests. It does not write anything to screen, and instead writes to an ObjectWritableMock.
Logger instance has two additional properties:
writableMock
:ObjectWritableMock
instancelogLines()
: a method that parses the JSON log to aLogDescriptor
format
Example:
import { createTestLogger } from '@scaleleap/logger'
const logger = createTestLogger()
logger.info('foo')
const logLines = logger.logLines()
expect(logLines[0].msg).toBe('foo')
log
An auto-instantiating logger instance.
An instance of logger will be created by using it.
Suitable for quick prototyping and quick scripts.
Example:
import { log } from '@scaleleap/logger'
log.info('Hello world')
Environment Variables
You can control logger behavior through a set of environment variables:
LOGGER_NAME
: Sets the logger name.LOGGER_LEVEL
: Sets the log level that will be emitted. See Log Levels.LOGGER_ENABLED
: Enables or disables the logger. Default istrue
.
Log Levels
The following log levels are supported:
trace
debug
info
warn
error
fatal
silent
The following defaults are used, based on NODE_ENV
values:
development
=debug
test
=error
production
=info
Heroku Log Parser
Parses Heroku logs and removes the prefix so that we can pipe it:
heroku logs | heroku-logs-parser | pino-pretty
AWS Lambda environment
Automatically adds the following environment variables to base
, when running in the AWS Lambda
environment:
{
memorySize: process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE,
region: process.env.AWS_REGION,
runtime: process.env.AWS_EXECUTION_ENV,
version: process.env.AWS_LAMBDA_FUNCTION_VERSION,
}
Contributing
This repository uses Conventional Commit style commit messages.
Authors or Acknowledgments
- Roman Filippov (Scale Leap)
License
This project is licensed under the MIT License.