Skip to main content

Logger

The logger module gives you a nice and structured way to log things to STDOUT or STDERR. A logger comes decorated with metadata, such as a correlation ID, which is outputed alongside each log lines, allowing for easier tracking and debugging. Typically, a new logger instance will be created on each request, readily available with context.logger. See Logging's recipe for usage examples.

Methods

log()

Equivalent to console.log.

error()

Equivalent to console.error.

warn()

Equivalent to console.warn.

info()

Equivalent to console.info.

debug()

Equivalent to console.debug.

decorate()

Merges a new set of metadata onto the existing one. All future logs will contain this data.

getMetadata()

Returns existing metadata.

setMetadata()

Adds a new key/value pair to the metadata object. Key cannot be 'message', has it is reserved for the actual log message.

clearMetadata()

Wipes all metadata.

Types

Value

The logging functions (log, error, warn, info, debug) will generate the payload to log by merging the metadata and the actual message we want to log during the current call.

Value defines a loggable Object that can have multiple levels, as long as the end values are one of the primitive values defined below.

type PrimitiveValue = undefined | null | string | string[] | number | number[] | boolean | boolean[];
type Value = {
[key: string]: PrimitiveValue | Value;
};

Metadata

Additional information to be sent with a request. An object with primitive values (see Value above) that must not include a first level key message, which is reserved for the actual log message.

export type Metadata = Value & { message?: never };