A logger interface. It provides methods to log messages at different severity levels.
const logger = getLogger("category"); logger.debug `A debug message with ${value}.`; logger.info `An info message with ${value}.`; logger.warn `A warning message with ${value}.`; logger.error `An error message with ${value}.`; logger.fatal `A fatal error message with ${value}.`;
Get a child logger with the given subcategory.
const logger = getLogger("category"); const subLogger = logger.getChild("sub-category");
The above code is equivalent to:
const logger = getLogger("category"); const subLogger = getLogger(["category", "sub-category"]);
Get a logger with contextual properties. This is useful for log multiple messages with the shared set of properties.
const logger = getLogger("category"); const ctx = logger.with({ foo: 123, bar: "abc" }); ctx.info("A message with {foo} and {bar}."); ctx.warn("Another message with {foo}, {bar}, and {baz}.", { baz: true });
The above code is equivalent to:
const logger = getLogger("category"); logger.info("A message with {foo} and {bar}.", { foo: 123, bar: "abc" }); logger.warn( "Another message with {foo}, {bar}, and {baz}.", { foo: 123, bar: "abc", baz: true }, );
debug(message: TemplateStringsArray,...values: readonly unknown[],): void
Log a debug message. Use this as a template string prefix.
logger.debug `A debug message with ${value}.`;
debug(): void
Log a debug message with properties.
logger.debug('A debug message with {value}.', { value });
If the properties are expensive to compute, you can pass a callback that returns the properties:
logger.debug( 'A debug message with {value}.', () => ({ value: expensiveComputation() }) );
debug(callback: LogCallback): void
Lazily log a debug message. Use this when the message values are expensive to compute and should only be computed if the message is actually logged.
logger.debug(l => l`A debug message with ${expensiveValue()}.`);
info(message: TemplateStringsArray,...values: readonly unknown[],): void
Log an informational message. Use this as a template string prefix.
logger.info `An info message with ${value}.`;
Log an informational message with properties.
logger.info('An info message with {value}.', { value });
If the properties are expensive to compute, you can pass a callback that returns the properties:
logger.info( 'An info message with {value}.', () => ({ value: expensiveComputation() }) );
info(callback: LogCallback): void
Lazily log an informational message. Use this when the message values are expensive to compute and should only be computed if the message is actually logged.
logger.info(l => l`An info message with ${expensiveValue()}.`);
warn(message: TemplateStringsArray,...values: readonly unknown[],): void
Log a warning message. Use this as a template string prefix.
logger.warn `A warning message with ${value}.`;
Log a warning message with properties.
logger.warn('A warning message with {value}.', { value });
If the properties are expensive to compute, you can pass a callback that returns the properties:
logger.warn( 'A warning message with {value}.', () => ({ value: expensiveComputation() }) );
warn(callback: LogCallback): void
Lazily log a warning message. Use this when the message values are expensive to compute and should only be computed if the message is actually logged.
logger.warn(l => l`A warning message with ${expensiveValue()}.`);
error(message: TemplateStringsArray,...values: readonly unknown[],): void
Log an error message. Use this as a template string prefix.
logger.error `An error message with ${value}.`;
error(): void
Log an error message with properties.
logger.warn('An error message with {value}.', { value });
If the properties are expensive to compute, you can pass a callback that returns the properties:
logger.error( 'An error message with {value}.', () => ({ value: expensiveComputation() }) );
error(callback: LogCallback): void
Lazily log an error message. Use this when the message values are expensive to compute and should only be computed if the message is actually logged.
logger.error(l => l`An error message with ${expensiveValue()}.`);
fatal(message: TemplateStringsArray,...values: readonly unknown[],): void
Log a fatal error message. Use this as a template string prefix.
logger.fatal `A fatal error message with ${value}.`;
fatal(): void
Log a fatal error message with properties.
logger.warn('A fatal error message with {value}.', { value });
If the properties are expensive to compute, you can pass a callback that returns the properties:
logger.fatal( 'A fatal error message with {value}.', () => ({ value: expensiveComputation() }) );
fatal(callback: LogCallback): void
Lazily log a fatal error message. Use this when the message values are expensive to compute and should only be computed if the message is actually logged.
logger.fatal(l => l`A fatal error message with ${expensiveValue()}.`);