@scaleleap/logger
TypeScript icon, indicating that this package has built-in type declarations

1.9.13 • Public • Published

📦 @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 instance
  • logLines(): a method that parses the JSON log to a LogDescriptor 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 is true.

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

License

This project is licensed under the MIT License.

Badges

GitHub Workflow Status NPM License Coveralls Semantic Release

/@scaleleap/logger/

    Package Sidebar

    Install

    npm i @scaleleap/logger

    Weekly Downloads

    1

    Version

    1.9.13

    License

    MIT

    Unpacked Size

    56.5 kB

    Total Files

    61

    Last publish

    Collaborators

    • moltar
    • scalebot