2017-08-03 03:48:16 +02:00
|
|
|
const winston = require('winston');
|
|
|
|
const ip = require('ip');
|
2017-09-30 01:38:00 +02:00
|
|
|
const os = require('os');
|
2016-12-08 04:52:37 +01:00
|
|
|
|
2017-03-15 04:59:40 +01:00
|
|
|
winston.emitErrs = true;
|
2017-09-30 01:21:48 +02:00
|
|
|
|
2019-07-22 02:56:54 +02:00
|
|
|
const logger = new winston.Logger({
|
2017-09-30 01:38:00 +02:00
|
|
|
level: 'debug',
|
|
|
|
transports: [
|
|
|
|
new (winston.transports.Console)()
|
|
|
|
],
|
|
|
|
handleExceptions: true,
|
|
|
|
humanReadableUnhandledException: true,
|
|
|
|
exitOnError: false,
|
|
|
|
meta: true
|
2016-12-08 04:52:37 +01:00
|
|
|
});
|
|
|
|
|
2017-09-30 01:21:48 +02:00
|
|
|
// Setup logging for LogDNA cloud logging.
|
|
|
|
if (process.env.LOGDNA_API_KEY) {
|
2017-09-30 01:38:00 +02:00
|
|
|
require('logdna');
|
2018-01-20 06:11:52 +01:00
|
|
|
const logLevel = process.env.LOGDNA_LEVEL || 'info';
|
2017-09-30 01:38:00 +02:00
|
|
|
|
2019-07-22 02:56:54 +02:00
|
|
|
logger.add(winston.transports.Logdna, {
|
|
|
|
level: logLevel,
|
|
|
|
app: process.env.LOGDNA_APPNAME,
|
|
|
|
index_meta: true,
|
|
|
|
key: process.env.LOGDNA_API_KEY,
|
|
|
|
ip: ip.address(),
|
|
|
|
hostname: os.hostname()
|
|
|
|
});
|
|
|
|
|
|
|
|
logger.info(`[core] Started LogDNA winston transport. Running at log level ${logLevel}.`);
|
2017-03-15 04:55:22 +01:00
|
|
|
}
|
|
|
|
|
2016-12-08 04:52:37 +01:00
|
|
|
module.exports = logger;
|