Skip to main content

๐Ÿ“– API

The logger is able to take in both objects and strings in order to generate log messages. The interface looks like this:

logger.method([data],[message[, ...format strings]])

A few examples of how parameters can be passed into the logger

export function MyService({ logger }: TServiceParams) {

// Log a simple string
logger.info("log message");

// Log an object
logger.info({ data: { foo: "bar" } });

// Log an object with a message
logger.info({ data: { foo: "bar" } }, `some text`);
}

Both objects and strings are allowed as the 1st parameter, but the object must come first if both are provided. All arguments after that are consumed as a spread and are passed through to util.format to further format the message text.

SymbolUse
%sString
%dNumber
%iparseInt
%fparseFloat
%jJSON
%oObject (including non-enumerable properties)
%OObject
%cCSS (unused by Node)
%%Plain % symbol, does not consume an arg

๐Ÿ”Š Log Levelsโ€‹

This table describes the priority order (highest -> lowest) of log levels and the color provided to the context. Setting the LOG_LEVEL to a higher level will cause the lower-level ones to not be emitted.

Log LevelColor
fatalMagenta
errorRed
warnYellow
infoGreen
debugBlue
traceGray

Unless changed, log levels will default to trace. Providing boilerplate.LOG_LEVEL as a bootstrap configuration value can affect the logger from the very start of the bootstrap.

Attention: The level may change through the app lifecycle Values sourced from the user config will only affect the logger after the configuration step. This could result in lots of trace logs at the very start, then having them stop partway through bootstrap as the configurations update.

Log level printingโ€‹

By default, log levels will be be prefixed to contexts in order to preserve information where colors may not be available. If you prefer to only utilize colors in your setup, there is a flag to disable this functionality as part of bootstrap params