Command-fix/logging.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-08-03 01:48:16 +00:00
const config = require('config');
const winston = require('winston');
const logdna = require('logdna');
const ip = require('ip');
const os = require("os");
2016-12-08 03:52:37 +00:00
2017-03-15 03:59:40 +00:00
winston.emitErrs = true;
2017-08-03 01:48:16 +00:00
const logger = new winston.Logger({
2016-12-08 03:52:37 +00:00
transports: [
2017-07-09 03:48:58 +00:00
new winston.transports.File({
2017-08-03 01:48:16 +00:00
filename: 'log.log',
level: 'debug'
2016-12-08 03:52:37 +00:00
})
],
2017-03-15 03:55:22 +00:00
handleExceptions: true,
2017-08-03 01:48:16 +00:00
humanReadableUnhandledException: true,
exitOnError: false,
meta: true,
2016-12-08 03:52:37 +00:00
});
2017-08-03 01:48:16 +00:00
if (config.enableLogdnaLogging === true && config.logdnaKey) {
2017-03-15 03:55:22 +00:00
// Setup logging for LogDNA cloud logging.
logger.add(winston.transports.Logdna, {
2017-03-15 04:03:38 +00:00
level: 'info',
2017-08-03 01:48:16 +00:00
index_meta: true,
2017-03-15 03:55:22 +00:00
key: config.logdnaKey,
ip: ip.address(),
hostname: os.hostname(),
2017-08-03 01:48:16 +00:00
app: 'services-services'
});
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-15 03:55:22 +00:00
});
}
2016-12-08 03:52:37 +00:00
module.exports = logger;