new winston.transports.Console({ timestamp: () => dayjs().format('HH:mm:ss'), formatter: options => { transports.push(new winston.transports.File({ name: 'error-file', label: logName, filename: path.join(logDir, `${logName}-error.log`), })); transports.push(new winston.transports.File({ name: 'log-file', label: logName,
winston.add(winston.transports.File, { filename: `${config.logs.path}/scrapoxy_${moment().format('YYYYMMDD_HHmmss')}.log`, json: false,
function Logger (config) { winston.Logger.call(this); var self = this; _.forEach(config, function (cfg, key) { self.add(winston.transports[cfg.type], _.assignIn({ name: key }, cfg.options)); }); }
/** * Stop logging to a file */ static deactivateFileLogging() { winston.remove(winston.transports.File); }
// can be much more flexible than that O_o function getLogger (module) { let path = module.filename.split("/").slice(-2).join("/"); return new winston.Logger({ transports: [ new winston.transports.Console({ colorize: true, level: "debug", label: path }) ] }); }
/** * Start logging to a file * @param {string} filename */ static setFileLogging(filename) { filename = logDir + filename; if (!filename.endsWith(logExt)) { filename += logExt; } console.log(`${chalk.bgMagenta.bold('[LOG] Starting log file:' + filename)}`); winston.add(winston.transports.File, { filename, timestamp: true }); }
logger.add(winston.transports.Console, { formatter: function (options) { return config.colorize(options.level, options.level.toUpperCase()) + ' ' + (options.message ? options.message : '') + (options.meta && Object.keys(options.meta).length ? '\n\t' + JSON.stringify(options.meta) : '' ); }, handleExceptions: true });
describe("logger", function () { before(function() { lf.logger.clear(); lf.logger.add(winston.transports.Memory); }); it("should exist in lambda-formation", function () { assert.isObject(lf.logger); assert.isFunction(lf.logger.log); }); it("should log only info messages by default", function () { lf.logger.log('debug', 'foobar1'); lf.logger.log('debug', 'foobar2'); lf.logger.log('info', 'foobar1'); lf.logger.log('info', 'foobar2'); assert.include(lf.logger.transports['memory'].writeOutput, 'info: foobar1'); assert.notInclude(lf.logger.transports['memory'].writeOutput, 'debug: foobar1'); }); });
init () { let logLevel = this.logLevel; this.client = new (winston.Logger)({ transports: [ new (winston.transports.Console)({ timestamp: function() { return moment().format('YYYY-MM-DD HH:mm:ss'); }, colorize: true, level: logLevel }), new (winston.transports.File)({ filename: this.logPath + '/' + this.logFile, level: 'error', json: false }) ] }); }
winston.add(winston.transports.Console, { 'timestamp': function() { // declare timestamp for log const now = new Date().toLocaleDateString('en-US', { day : 'numeric', month : 'short', hour : 'numeric', minute : 'numeric', second: 'numeric' }); return `${chalk.italic.magenta(now)}`; } });
const newDefaultLogger = () => { return new winston.Logger({ transports: [ new (winston.transports.Console)({colorize: true, timestamp: true}) ] }); }
function getLogger (logFilename) { return new winston.Logger({ transports: [ new winston.transports.File({ level: 'info', filename: logFilename, handleExceptions: true, json: false, maxsize: 5242880, // 5MB maxFiles: 5, colorize: false }) ], exitOnError: false }); }
const newDefaultLogger = () => { return new winston.Logger({ transports: [ new (winston.transports.Console)({colorize: true, timestamp: true}) ] }); }
function getLogger(module) { const path = module.filename.split('/').slice(-2).join('/'); return new winston.Logger({ transports: [ new winston.transports.Console({ colorize: true, level: 'debug', label: path, }), ], }); }
function getLogger(module) { var path = module.filename.split('/').slice(-2).join('/'); //отобразим метку с именем файла, который выводит сообщение return new winston.Logger({ transports : [ new winston.transports.Console({ colorize: true, level: 'debug', // label: path }) ] }); }