@egodigital/egoose
Version:
Helper classes and functions for Node.js 10 or later.
199 lines (198 loc) • 4.38 kB
TypeScript
/**
* This file is part of the @egodigital/egoose distribution.
* Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
*
* @egodigital/egoose is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, version 3.
*
* @egodigital/egoose is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import * as moment from 'moment';
/**
* A log action.
*
* @param {LogContext} context The context.
*/
export declare type LogAction = (context: LogContext) => void;
/**
* A log context.
*/
export interface LogContext {
/**
* The message.
*/
readonly message: any;
/**
* The optional tag.
*/
readonly tag?: string;
/**
* The timestamp.
*/
readonly time: moment.Moment;
/**
* The type.
*/
readonly type: LogType;
}
/**
* List of log types.
*/
export declare enum LogType {
/**
* Emergency
*/
Emerg = 0,
/**
* Alert
*/
Alert = 1,
/**
* Critical
*/
Crit = 2,
/**
* Error
*/
Err = 3,
/**
* Warning
*/
Warn = 4,
/**
* Notice
*/
Notice = 5,
/**
* Informational
*/
Info = 6,
/**
* Debug
*/
Debug = 7,
/**
* Trace
*/
Trace = 8
}
/**
* A logger.
*/
export declare class Logger {
private readonly _ACTIONS;
/**
* Adds a log action.
*
* @param {LogAction} action The action.
*
* @return this
*/
addAction(action: LogAction): this;
/**
* Logs an alert message.
*
* @param {any} msg The message to log.
* @param {string} [tag] Optional tag to log.
*
* @return this
*/
alert(msg: any, tag?: string): this;
/**
* Logs a critical message.
*
* @param {any} msg The message to log.
* @param {string} [tag] Optional tag to log.
*
* @return this
*/
crit(msg: any, tag?: string): this;
/**
* Logs a debug message.
*
* @param {any} msg The message to log.
* @param {string} [tag] Optional tag to log.
*
* @return this
*/
dbg(msg: any, tag?: string): this;
/**
* Logs an emergency message.
*
* @param {any} msg The message to log.
* @param {string} [tag] Optional tag to log.
*
* @return this
*/
emerg(msg: any, tag?: string): this;
/**
* Logs an error message.
*
* @param {any} msg The message to log.
* @param {string} [tag] Optional tag to log.
*
* @return this
*/
err(msg: any, tag?: string): this;
/**
* Logs an info message.
*
* @param {any} msg The message to log.
* @param {string} [tag] Optional tag to log.
*
* @return this
*/
info(msg: any, tag?: string): this;
/**
* Logs a message.
*
* @param {LogType} type The type.
* @param {any} msg The message to log.
* @param {string} tag The optional tag.
*
* @return this
*/
log(type: LogType, msg: any, tag?: string): this;
/**
* Logs a notice.
*
* @param {any} msg The message to log.
* @param {string} [tag] Optional tag to log.
*
* @return this
*/
note(msg: any, tag?: string): this;
/**
* Logs a trace message.
*
* @param {any} msg The message to log.
* @param {string} [tag] Optional tag to log.
*
* @return this
*/
trace(msg: any, tag?: string): this;
/**
* Logs a warning message.
*
* @param {any} msg The message to log.
* @param {string} [tag] Optional tag to log.
*
* @return this
*/
warn(msg: any, tag?: string): this;
}
/**
* Creates a new logger instance.
*
* @param {LogAction[]} [actions] One or more initial actions to add.
*
* @return {Logger} The new instance.
*/
export declare function createLogger(...actions: LogAction[]): Logger;