UNPKG

actionhero

Version:

The reusable, scalable, and quick node.js API server for stateless and stateful applications

47 lines (46 loc) 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.loggers = void 0; exports.log = log; const winston = require("winston"); const config_1 = require("./config"); const utils_1 = require("./utils"); // exported as `import { loggers } from "actionhero"` exports.loggers = []; config_1.config.general.paths.log.forEach((p) => { try { utils_1.utils.fileUtils.createDirSafely(p); } catch (error) { if (error.code !== "EEXIST") { throw error; } } }); exports.loggers = config_1.config.logger.loggers.map((loggerBuilder) => { const resolvedLogger = loggerBuilder(config_1.config); return winston.createLogger(resolvedLogger); }); /** * Log a message, with optional metadata. The message can be logged to a number of locations (stdio, files, etc) as configured via config/logger.js * * The most basic use. Will assume 'info' as the severity: `log('hello')` * Custom severity: `log('OH NO!', 'warning')` * Custom severity with a metadata object: `log('OH NO, something went wrong', 'warning', { error: new Error('things are busted') })` * * The default log levels are: `emerg: 0, alert: 1, crit: 2, error: 3, warning: 4, notice: 5, info: 6, debug: 7`. * Logging levels in winston conform to the severity ordering specified by RFC5424: severity of all levels is assumed to be numerically ascending from most important to least important. * Learn more at https://github.com/winstonjs/winston */ function log(message, severity = "info", data) { exports.loggers.map((logger) => { if (logger.levels[severity] === undefined) { severity = "info"; } const args = [severity, message]; if (data !== null && data !== undefined) { args.push(data); } return logger.log.apply(logger, args); }); }