The winston-wingman module supplies common defaults to the winston logger. It also offers an easy interface for modifying transports on the fly and encapsulates the underlying loading. Once the module has loaded, you can use either the exposed winston object, or just require winston in the normal way in your source files. Usually the top level file in a project will require winston-wingman and make any configuration changes. All other modules will just require the winston module. See the documentation of the winston module for additional features; https://github.com/winstonjs/winston.
$ npm install winston-wingman --save
// In the main startup file configure the logger
let logger = require('winston-wingman');
let winston = logger.winston;
// All of your other js files that log, can use either below
// let winston = require('winston');
// let winston = require('winston-wingman').winston;
// change the name of the logfile to be used.
logger.mergeFileTransport({filename: 'logs/myspecialname.log'});
winston.info('logging is easy');
##Default Configuration
If no additional configurations are used, here are the defaults:
let currentConsoleTransport = {
timestamp: (function() {return new Date().toLocaleString();}) ,
colorize: true,
level: 'info',
handleExceptions: true,
humanReadableUnhandledException: true
};
let currentFileTransport = {
filename: 'app.log',
timestamp: (function() {return new Date().toLocaleString();}) ,
level: 'info',
handleExceptions: true,
humanReadableUnhandledException: true,
maxsize: 10000,
maxFiles: 5,
tailable: true,
json: false,
zippedArchive: true
};
The class is documented with JSDoc.
Bill Hodges