ecs-logs-js
Version:
Simple Node.js console logger that outputs human friendly and ecs-logs compatible messages
88 lines (87 loc) • 3.11 kB
TypeScript
declare const LEVELS_MAP: {
emerg: number;
alert: number;
crit: number;
error: number;
warn: number;
notice: number;
info: number;
debug: number;
};
/** Available log levels. */
export type LEVEL = keyof typeof LEVELS_MAP;
/** Options that can be passed to the Logger constructor. */
export interface LoggerOptions {
/**
* Sets the maximum log level that will be output. By setting this option to 'info', it can be used to disable debug logs in production.
* @default 'debug'
*/
level?: LEVEL;
/**
* Enables the human friendly development output.
* @default process.env.NODE_ENV === 'development'
*/
devMode?: boolean;
}
/** Creates a new logger instance. */
export declare class Logger {
level: LEVEL;
devMode: boolean;
constructor(options?: LoggerOptions);
/**
* Logs a message at the given log level.
* @param level Log level for the message.
* @param message The message to log.
* @param data Any additional data to log with the message. This can be any type.
*/
log: (level: LEVEL, message: string, data?: unknown) => void;
/**
* Logs a message at the EMERG log level.
* @param message The message to log.
* @param data Any additional data to log with the message. This can be any type.
*/
emerg: (message: string, data?: unknown) => void;
/**
* Logs a message at the ALERT log level.
* @param message The message to log.
* @param data Any additional data to log with the message. This can be any type.
*/
alert: (message: string, data?: unknown) => void;
/**
* Logs a message at the CRIT log level.
* @param message The message to log.
* @param data Any additional data to log with the message. This can be any type.
*/
crit: (message: string, data?: unknown) => void;
/**
* Logs a message at the ERROR log level.
* @param message The message to log.
* @param data Any additional data to log with the message. This can be any type.
*/
error: (message: string, data?: unknown) => void;
/**
* Logs a message at the WARN log level.
* @param message The message to log.
* @param data Any additional data to log with the message. This can be any type.
*/
warn: (message: string, data?: unknown) => void;
/**
* Logs a message at the NOTICE log level.
* @param message The message to log.
* @param data Any additional data to log with the message. This can be any type.
*/
notice: (message: string, data?: unknown) => void;
/**
* Logs a message at the INFO log level.
* @param message The message to log.
* @param data Any additional data to log with the message. This can be any type.
*/
info: (message: string, data?: unknown) => void;
/**
* Logs a message at the DEBUG log level.
* @param message The message to log.
* @param data Any additional data to log with the message. This can be any type.
*/
debug: (message: string, data?: unknown) => void;
}
export {};