JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 156
  • Score
    100M100P100Q79876F
  • License MIT

A Monolog-inspired logging library for Node.js

Package Exports

  • @livy/logger
  • @livy/logger/lib/logger-factory.js
  • @livy/logger/lib/logger-factory.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@livy/logger) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@livy/logger

The Livy logger factory is at the heart of every logger, as it creates a new logger instance.

Basic Example

const { createLogger } = require('@livy/logger')

const logger = createLogger('app-logger')

Installation

Install it via npm:

npm install @livy/logger

Options

The createLogger function takes a mandatory channel name as its first parameter. A second argument may be provided with object of options:

autoClose

Type: boolean

Default: true

Description: Whether to automatically run the logger's close method when the Node.js process exits / the browser page closes.

handlers

Type: Iterable<HandlerInterface | SyncHandlerInterface>

Default: []

Description: Handlers of the logger.

mode

Type: 'sync' | 'async' | 'mixed'

Default: 'mixed'

Description: The concurrency mode of the logger.

processors

Type: Iterable<ProcessorInterfaceOrFunction>

Default: []

Description: Processors of the logger.

timezone

Type: string (IANA name)

Default: The runtime's time zone, determined by the Intl API.

Description: The time zone the logger should use.

Logging

Logs can be created with the log() method. It takes a log level, a message and an optional context object:

logger.log('info', 'This is the logged message')

Note that the log method returns a Promise in async mode, so it should be awaited to avoid unexpected failures:

await logger.log('info', 'This is the logged message')

For each log level, there is a convenience method which allows omitting the level parameter:

logger.debug('This is a debug message')
logger.info('This is an info message')
logger.notice('This is a notice message')
logger.warning('This is a warning message')
logger.error('This is an error message')
logger.alert('This is an alert message')
logger.critical('This is a critical message')
logger.emergency('This is an emergency message')

Public API

reset()

Resetting a logger will reset all its handlers and processors which implement the ResettableInterface.

name (read-only)

The logger's channel name.

withName(name)

Clone the logger with a new name.

timezone (read-only)

The logger's IANA time zone name.