2017-08-02 21:48:16 -04:00
|
|
|
const config = require('config');
|
|
|
|
const winston = require('winston');
|
|
|
|
const logdna = require('logdna');
|
|
|
|
const ip = require('ip');
|
|
|
|
const os = require("os");
|
2016-12-07 22:52:37 -05:00
|
|
|
|
2017-03-14 23:59:40 -04:00
|
|
|
winston.emitErrs = true;
|
2017-08-02 21:48:16 -04:00
|
|
|
const logger = new winston.Logger({
|
2016-12-07 22:52:37 -05:00
|
|
|
transports: [
|
2017-07-08 23:48:58 -04:00
|
|
|
new winston.transports.File({
|
2017-08-02 21:48:16 -04:00
|
|
|
filename: 'log.log',
|
|
|
|
level: 'debug'
|
2016-12-07 22:52:37 -05:00
|
|
|
})
|
|
|
|
],
|
2017-03-14 23:55:22 -04:00
|
|
|
handleExceptions: true,
|
2017-08-02 21:48:16 -04:00
|
|
|
humanReadableUnhandledException: true,
|
|
|
|
exitOnError: false,
|
|
|
|
meta: true,
|
2016-12-07 22:52:37 -05:00
|
|
|
});
|
|
|
|
|
2017-08-02 21:48:16 -04:00
|
|
|
if (config.enableLogdnaLogging === true && config.logdnaKey) {
|
2017-03-14 23:55:22 -04:00
|
|
|
// Setup logging for LogDNA cloud logging.
|
|
|
|
logger.add(winston.transports.Logdna, {
|
2017-03-15 00:03:38 -04:00
|
|
|
level: 'info',
|
2017-08-02 21:48:16 -04:00
|
|
|
index_meta: true,
|
2017-03-14 23:55:22 -04:00
|
|
|
key: config.logdnaKey,
|
|
|
|
ip: ip.address(),
|
|
|
|
hostname: os.hostname(),
|
2017-08-06 21:11:09 -04:00
|
|
|
app: config.app
|
2017-08-02 21:48:16 -04:00
|
|
|
});
|
|
|
|
logger.debug('[logging] Started LogDNA winston transport.');
|
|
|
|
} else if (config.enableLogdna === true) {
|
|
|
|
throw "Attempted to enable LogDNA transport without a key!";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.enableConsoleLogging === true) {
|
|
|
|
logger.add(winston.transports.Console, {
|
|
|
|
level: 'silly',
|
|
|
|
colorize: true
|
2017-03-14 23:55:22 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-07 22:52:37 -05:00
|
|
|
module.exports = logger;
|