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