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

    1.0.5 • Public • Published

    @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.

    Install

    npm i @livy/logger

    DownloadsWeekly Downloads

    1

    Version

    1.0.5

    License

    MIT

    Unpacked Size

    33.9 kB

    Total Files

    18

    Last publish

    Collaborators

    • loilo