Class Logger

Source
Expand description

A logger for writing log entries with various severity levels.

import { Logger, LogLevel } from '../src/index.js';

const logger = new Logger('MyApp', {
version: 'v1.0.0',
});

Logger.logLevel = LogLevel.DEBUG;

logger.info('Hello, world!');
logger.error('Something went wrong.', { error: new Error('An error occurred.') });
logger.debug('This message will be logged.');

Constructors§

Source§

new Logger(context?: string, labels?: LogLabels): Logger

Properties§

Source§

public context?: string

The context for this logger instance.

Source§

public labels?: LogLabels

The labels for this logger instance.

Source§

public logLevel?: LogLevel

The minimum severity level to log for this logger instance.

Source§

public static context?: string

The default context for loggers.

Source§

public static instance: ILogger = ...

The default logger instance.

Source§

public static labels?: LogLabels

The default labels for loggers.

Source§

public static logLevel: LogLevel = LogLevel.INFO

The minimum severity level to log.

Source§

public static writer: ILogWriter = ...

The writer to use for logging.

Methods§

Source§

alert(message: string, payload?: LogPayload): void

A person must take an action immediately.

Example:

Logger.alert('An error occurred.', { status: 500, error: new Error('Something went wrong.') });
Source§

critical(message: string, payload?: LogPayload): void

Critical events cause more severe problems or outages.

Example:

Logger.critical('An error occurred.', { status: 500, error: new Error('Something went wrong.') });
Source§

debug(message: string, payload?: LogPayload): void

Debug or trace information.

Example:

Logger.debug('The server is running.');
Logger.debug('The server is running.', { port: 3000 });
Source§

default(message: string, payload?: LogPayload): void

The log entry has no assigned severity level.

Example:

Logger.default('The server is running.');
Logger.default('The server is running.', { port: 3000 });
Source§

emergency(message: string, payload?: LogPayload): void

One or more systems are unusable.

Example:

Logger.emergency('An error occurred.', { status: 500, error: new Error('Something went wrong.') });
Source§

error(message: string, payload?: LogPayload): void

Error events are likely to cause problems.

Example:

Logger.error('An error occurred.', { status: 500, error: new Error('Something went wrong.') });
Source§

info(message: string, payload?: LogPayload): void

Routine information, such as ongoing status or performance.

Example:

Logger.info('The server is running.');
Logger.info('The server is running.', { port: 3000 });
Source§

notice(message: string, payload?: LogPayload): void

Normal but significant events, such as start up, shut down, or a configuration change.

Example:

Logger.notice('The server is running.');
Logger.notice('The server is running.', { port: 3000 });
Source§

warning(message: string, payload?: LogPayload): void

Warning events might cause problems.

Example:

Logger.warning('Unauthorized access.', { status: 401 });
Source§

alert(message: string, payload?: LogPayload): void

A person must take an action immediately.

Example:

Logger.alert('An error occurred.', { status: 500, error: new Error('Something went wrong.') });
Source§

critical(message: string, payload?: LogPayload): void

Critical events cause more severe problems or outages.

Example:

Logger.critical('An error occurred.', { status: 500, error: new Error('Something went wrong.') });
Source§

debug(message: string, payload?: LogPayload): void

Debug or trace information.

Example:

Logger.debug('The server is running.');
Logger.debug('The server is running.', { port: 3000 });
Source§

default(message: string, payload?: LogPayload): void

The log entry has no assigned severity level.

Example:

Logger.default('The server is running.');
Logger.default('The server is running.', { port: 3000 });
Source§

emergency(message: string, payload?: LogPayload): void

One or more systems are unusable.

Example:

Logger.emergency('An error occurred.', { status: 500, error: new Error('Something went wrong.') });
Source§

error(message: string, payload?: LogPayload): void

Error events are likely to cause problems.

Example:

Logger.error('An error occurred.', { status: 500, error: new Error('Something went wrong.') });
Source§

info(message: string, payload?: LogPayload): void

Routine information, such as ongoing status or performance.

Example:

Logger.info('The server is running.');
Logger.info('The server is running.', { port: 3000 });
Source§

notice(message: string, payload?: LogPayload): void

Normal but significant events, such as start up, shut down, or a configuration change.

Example:

Logger.notice('The server is running.');
Logger.notice('The server is running.', { port: 3000 });
Source§

warning(message: string, payload?: LogPayload): void

Warning events might cause problems.

Example:

Logger.warning('Unauthorized access.', { status: 401 });