@mdf.js/logger
Version:
MMS - API Logger - Enhanced logger library for mms artifacts
115 lines • 5.31 kB
JavaScript
;
/**
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DebugLogger = void 0;
const tslib_1 = require("tslib");
const crash_1 = require("@mdf.js/crash");
const debug_1 = tslib_1.__importDefault(require("debug"));
class DebugLogger {
/**
* Creates a new instance of the default logger
* @param name - Name of the provider
*/
constructor(name) {
this.name = name;
/**
* 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
*/
this.silly = (message, uuid, context, ...meta) => {
this.logger.extend('silly')(message);
for (const entry of meta) {
if (typeof entry === 'object' && entry !== null && !Array.isArray(entry)) {
this.logger.extend('silly')('o%', entry);
}
}
};
/**
* 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
*/
this.debug = (message, uuid, context, ...meta) => {
this.logger.extend('debug')(message);
};
/**
* 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
*/
this.verbose = (message, uuid, context, ...meta) => {
this.logger.extend('verbose')(message);
};
/**
* 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
*/
this.info = (message, uuid, context, ...meta) => {
this.logger.extend('info')(message);
};
/**
* 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
*/
this.warn = (message, uuid, context, ...meta) => {
this.logger.extend('warn')(message);
};
/**
* 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
*/
this.error = (message, uuid, context, ...meta) => {
this.logger.extend('error')(message);
};
/**
* 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 rawError - crash error instance
* @param context - context (class/function) where this logger is logging
*/
this.crash = (rawError, context) => {
const error = crash_1.Crash.from(rawError);
for (const entry of error.trace()) {
this.logger.extend('error')(entry);
}
};
/** Stream logger */
this.stream = {
write: (message) => {
const data = JSON.parse(message);
this.logger.extend(data.level)(data.message);
},
};
this.logger = (0, debug_1.default)(this.name);
}
}
exports.DebugLogger = DebugLogger;
//# sourceMappingURL=DebugLogger.js.map