Core
Logger v1.x
2

KuzzleLogger #

The Node logger. In a Kuzzle application, app.log is a KuzzleLogger.

import { KuzzleLogger } from 'kuzzle-logger';

Constructor #

constructor(config: KuzzleLoggerConfig)

Parameters #

Properties #

level #

get level(): string
set level(level: string)

Get or set the current logging level. Valid levels are:

  • 'fatal'
  • 'error'
  • 'warn'
  • 'info'
  • 'debug'
  • 'trace'
  • 'silent' (nothing is logged)

pino #

get pino(): Logger

Get the underlying Pino logger instance.

Methods #

Logging Methods #

All logging methods share similar signatures:

method(obj: object, msg?: string, ...args: any[]): void
method(obj: unknown, msg?: string, ...args: any[]): void
method(msg: string, ...args: any[]): void
  • trace(): Log at trace level
  • debug(): Log at debug level
  • info(): Log at info level
  • warn(): Log at warn level
  • error(): Log at error level
  • fatal(): Log at fatal level

Each method can be called in multiple ways:

  1. With an object and optional message:
    logger.info({ user: 'john' }, 'User logged in');
  2. With just a message:
    logger.info('System started');
  3. With an error object:
    logger.error(new Error('Connection failed'));

flush() #

async flush(): Promise<void>

Writes the buffered entries to their destination. For example, call it before the process exits so that the last entries are not lost.

child(namespace: string) #

child(namespace: string): KuzzleLogger

Creates a child logger with the specified namespace. The child logger inherits all settings from its parent and adds the namespace to the merging object. Its level follows the parent level, even when the parent level changes after the child is created, until a level is set on the child itself.