UNPKG

@node-elion/utils

Version:

Super scalable enterprise Node.js server library

120 lines 4.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Logger = void 0; const types_js_1 = require("./types.js"); class Logger { static child(options) { return new Logger(options); } constructor(options) { var _a, _b, _c, _d, _e; this.options = options || {}; if (this.options.parentLogger) { this.name = (_a = this.options.name) !== null && _a !== void 0 ? _a : ""; this.nameLevel = [ ...this.options.parentLogger.nameLevel, this.name, ]; this.level = (_b = options.level) !== null && _b !== void 0 ? _b : this.options.parentLogger.level; this.callback = this.options.parentLogger.callback.bind(this.options.parentLogger); } else { this.level = (_c = this.options.level) !== null && _c !== void 0 ? _c : "info"; this.callback = (_d = this.options.callback) !== null && _d !== void 0 ? _d : (() => { }); this.name = (_e = this.options.name) !== null && _e !== void 0 ? _e : ""; this.nameLevel = [this.name]; } } child(arg) { if (typeof arg === "string") { return this.child({ name: arg, parentLogger: this, }); } return new Logger(Object.assign(Object.assign({}, arg), { parentLogger: this })); } execute(level, ...message) { if (types_js_1.LoggerLevelsArray.indexOf(level) <= types_js_1.LoggerLevelsArray.indexOf(this.level)) { this.callback({ level, message, meta: { level: this.nameLevel, }, }); } } /** * Logs error messages. * Use this logger level to log errors that occur during your program's execution. * @param message The error message(s) to log */ error(...message) { this.execute("error", ...message); } /** * Logs warning messages. * Use this logger level to log non-error messages that could potentially lead to application errors. * @param message The warning message(s) to log */ warn(...message) { this.execute("warn", ...message); } /** * Logs basic information messages. * Use this logger level for informational messages to track your application's normal behavior. * @param message The information message(s) to log */ info(...message) { this.execute("info", ...message); } /** * Also logs informational messages. The same as the info logger level. * @param message The message(s) to log */ log(...message) { this.execute("info", ...message); } /** * Logs HTTP requests. * Use this logger level to log the details of HTTP requests and responses. * @param message The HTTP request/response message(s) to log */ http(...message) { this.execute("http", ...message); } /** * Provides detailed logs. Use this logger level for detailed debug information beyond what you'd log for debugging. * @param message The message(s) to log in verbose mode */ verbose(...message) { this.execute("verbose", ...message); } /** * Logs debug-level messages. Use this logger level to log information helpful in debugging. * @param message The debug message(s) to log */ debug(...message) { this.execute("debug", ...message); } /** * Provides the most detailed logs. * This is the highest level of logging and includes all levels of messages. * @param message The message(s) to log in silly mode */ silly(...message) { this.execute("silly", ...message); } /** * Also provides the most detailed logs. * The same as the silly logger level. * @param message The message(s) to log in trace mode */ trace(...message) { this.execute("silly", ...message); } } exports.Logger = Logger; //# sourceMappingURL=logger.js.map