UNPKG

@mdf.js/logger

Version:

MMS - API Logger - Enhanced logger library for mms artifacts

171 lines 7.28 kB
/** * Copyright 2024 Mytra Control S.L. All rights reserved. * * Use of this source code is governed by an MIT-style license that can be found in the LICENSE file * or at https://opensource.org/licenses/MIT. */ import { Boom, Crash, Multi } from '@mdf.js/crash'; import Joi from 'joi'; import { ConsoleTransportConfig } from './console'; import { FileTransportConfig } from './file'; import { FluentdTransportConfig } from './fluentd'; import { LoggerInstance } from './types'; /** Logger transports configuration interface */ export interface LoggerConfig { console?: ConsoleTransportConfig; file?: FileTransportConfig; fluentd?: FluentdTransportConfig; } /** Logger transports validation schema */ export declare const LoggerSchema: Joi.ObjectSchema<LoggerConfig>; /** Class Logger, manage the event and log register process for netin artifacts */ export declare class Logger implements LoggerInstance { private label; /** Debug logger for development and deep troubleshooting */ private readonly _debug; /** Default config */ private readonly defaultConfig; /** Actual logger configuration */ private _config; /** Logger de context dentro de Winston */ private readonly logger; /** Transports */ private transports; /** Number of actual configured transports */ private numberOfTransports; /** Actual process id */ private readonly pid; /** Logger configuration was wrong flag */ private errorInConfig; /** Error in the configuration */ private _configError; /** Logger instance UUID */ private readonly uuid; /** Flag that indicate if the component is running in a docker instance */ private _isDocker; /** Create a netin logger instance with default values */ constructor(); /** * Create a netin logger instance with default values * @param label - logger label */ constructor(label: string); /** * Create a netin logger instance with default values * @param label - logger label * @param configuration - logger configuration */ constructor(label: string, configuration?: LoggerConfig); /** * Establish the logger configuration * @param label - Logger label * @param configuration - logger configuration */ private initialize; /** * Establish the logger configuration * @param label - Logger label * @param configuration - logger configuration */ setConfig(label: string, configuration: LoggerConfig): void; /** * Establish the file transport configuration * @param label - Logger label * @param configuration - logger configuration */ private setFileTransport; /** * Establish the console transport configuration * @param label - Logger label * @param configuration - logger configuration */ private setConsoleTransport; /** * Establish the fluentd transport configuration * @param label - Logger label * @param config - logger configuration */ private setFluentdTransport; /** * Log events in the SILLY level: all the information in a very detailed way. * This level used to be necessary only in the development process, and the meta data used to be * the results of the operations. * @param message - human readable information to log * @param uuid - unique identifier for the actual job/task/request process * @param context - context (class/function) where this logger is logging * @param meta - extra information */ silly(message: string, uuid?: string, context?: string, ...meta: any[]): void; /** * Log events in the DEBUG level: all the information in a detailed way. * This level used to be necessary only in the debugging process, so not all the data is * reported, only the related with the main processes and tasks. * @param message - human readable information to log * @param uuid - unique identifier for the actual job/task/request process * @param context - context (class/function) where this logger is logging * @param meta - extra information */ debug(message: string, uuid?: string, context?: string, ...meta: any[]): void; /** * Log events in the VERBOSE level: trace information without details. * This level used to be necessary only in system configuration process, so information about * the settings and startup process used to be reported. * @param message - human readable information to log * @param uuid - unique identifier for the actual job/task/request process * @param context - context (class/function) where this logger is logging * @param meta - extra information */ verbose(message: string, uuid?: string, context?: string, ...meta: any[]): void; /** * Log events in the INFO level: only relevant events are reported. * This level is the default level. * @param message - human readable information to log * @param uuid - unique identifier for the actual job/task/request process * @param context - context (class/function) where this logger is logging * @param meta - extra information */ info(message: string, uuid?: string, context?: string, ...meta: any[]): void; /** * Log events in the WARN level: information about possible problems or dangerous situations. * @param message - human readable information to log * @param uuid - unique identifier for the actual job/task/request process * @param context - context (class/function) where this logger is logging * @param meta - extra information */ warn(message: string, uuid?: string, context?: string, ...meta: any[]): void; /** * Log events in the ERROR level: all the errors and problems with detailed information. * @param message - human readable information to log * @param uuid - unique identifier for the actual job/task/request process * @param context - context (class/function) where this logger is logging * @param meta - extra information */ error(message: string, uuid?: string, context?: string, ...meta: any[]): void; /** * Log events in the ERROR level: all the information in a very detailed way. * This level used to be necessary only in the development process. * @param error - crash error instance * @param context - context (class/function) where this logger is logging */ crash(error: Crash | Boom | Multi, context?: string): void; /** Stream de escritura del propio logger */ get stream(): { write: (str: string) => void; }; /** Logger config */ get config(): LoggerConfig; /** Logger configuration error flag */ get hasError(): boolean; /** Logger configuration errors, if exist */ get configError(): Multi | undefined; /** Determine if the component is running in a docker instance or not */ private isDocker; /** * Set at least one transport to true if no transport is set but a configuration has been * indicated * @param finalConfig - Final configuration * @param configuration - Initial configuration */ private atLeastOne; } //# sourceMappingURL=logger.d.ts.map