Logger

utils/logger~ Logger

new Logger()

Implementation of the Bunyan logger that provides a static access method to retrieve configuration logger instances and to extend the logging output behavior to include our request transaction data as additional log metadata.

Implementation of the Bunyan logger that provides a static access method to retrieve configuration logger instances and to extend the logging output behavior to include our request transaction data as additional log metadata.

The configuration object must be of the following shape: { default_name: [name], handlers: { [name]: { name: [name], level: [valid level], } }, streams: { // TBD }, }

Source:
See:

Extends

  • Bunyan

Methods

(static) addLogger(loggerName, loggerInstance) → {Object}

Adds the provided logger instance to the cache.

Adds the provided logger instance to the cache.

Parameters:
Name Type Description
loggerName string | Object
loggerInstance Object | null

(optional) Provide the logger object if also providing the logger name

Source:

(static) configure(config) → {void}

Applies the provided config as the static configuration for all loggers.

Applies the provided config as the static configuration for all loggers.

Parameters:
Name Type Description
config Object
Source:

(static) createFallbackLogger(The) → {Object}

Creates and returns a new logger of the name loggerName using the DEFAULT_LOGGER.

Creates and returns a new logger of the name loggerName using the DEFAULT_LOGGER.

Parameters:
Name Type Description
The string

requested logger name

Source:

(static) createLogger(The) → {Object}

Creates a new logger for the given logger name.

Creates a new logger for the given logger name. If the requested name does not exist in the config, then a fallback logger is provided.

Parameters:
Name Type Description
The string

requested logger name

Source:

(static) getLogger(name) → {Object}

Retrieve a logger instance by name by looking up the logger in the logger cache.

Retrieve a logger instance by name by looking up the logger in the logger cache. If no logger name is provide, the default logger (root) is returned. If no logger by the provided name exists and the logger name is found in the configuration, then a new logger is created and returned; otherwise an Error is thrown.

Parameters:
Name Type Description
name string

The requested logger name

Source:

(static) setDefaultLogger(loggerInstance) → {void}

Adds the provided logger instance to the cache and sets the default logger name to config.

Adds the provided logger instance to the cache and sets the default logger name to config.

Parameters:
Name Type Description
loggerInstance Object

The default logger instance

Source:

_emit(rec, noemit) → {void}

Extends Bunyan's functionality to include the transaction data in the log output.

Extends Bunyan's functionality to include the transaction data in the log output. Calls Bunyan._emit with the modified log record. _emit is responsible for writing a log record to the logger instance's output.

Parameters:
Name Type Description
rec Object

The log record to emit

noemit boolean

Flag controlling if the current record should be emitted or not

Source:

serializeTransaction(Object) → {Object}

Generates a formatted object from the transaction data attached to the current process.domain.

Generates a formatted object from the transaction data attached to the current process.domain. If such a transaction exists, get the transaction's ID and the request context (Koa context). Attach the transaction ID to the record, as well as the session ID, if a session exists, and some basic information about the current logged-in user, if a user exists.

The session is found on the context as ctx.session, and the use is found on the context as ctx.user.

Parameters:
Name Type Description
Object rec

The log record to emit

Source: