2022-09-14 10:30:27 +02:00
|
|
|
import * as winston from 'winston';
|
2020-05-02 07:35:33 +02:00
|
|
|
import * as ip from 'ip';
|
|
|
|
import * as os from 'os';
|
2016-12-08 04:52:37 +01:00
|
|
|
|
2020-05-02 07:35:33 +02:00
|
|
|
const logger = winston.createLogger({
|
2017-09-30 01:38:00 +02:00
|
|
|
level: 'debug',
|
|
|
|
transports: [
|
2020-05-02 07:35:33 +02:00
|
|
|
new (winston.transports.Console)({
|
|
|
|
format: winston.format.combine(
|
|
|
|
winston.format.colorize(),
|
|
|
|
winston.format.simple()
|
|
|
|
),
|
|
|
|
handleExceptions: true
|
|
|
|
})
|
2017-09-30 01:38:00 +02:00
|
|
|
],
|
2021-10-28 23:38:02 +02:00
|
|
|
exitOnError: 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) {
|
2020-05-02 07:35:33 +02:00
|
|
|
const logdnaWinston = require('logdna-winston');
|
2018-01-20 06:11:52 +01:00
|
|
|
const logLevel = process.env.LOGDNA_LEVEL || 'info';
|
2017-09-30 01:38:00 +02:00
|
|
|
|
2020-05-02 07:35:33 +02:00
|
|
|
logger.add(new logdnaWinston({
|
2019-07-22 02:56:54 +02:00
|
|
|
level: logLevel,
|
|
|
|
app: process.env.LOGDNA_APPNAME,
|
|
|
|
index_meta: true,
|
|
|
|
key: process.env.LOGDNA_API_KEY,
|
|
|
|
ip: ip.address(),
|
|
|
|
hostname: os.hostname()
|
2020-05-02 07:35:33 +02:00
|
|
|
}));
|
2019-07-22 02:56:54 +02:00
|
|
|
|
|
|
|
logger.info(`[core] Started LogDNA winston transport. Running at log level ${logLevel}.`);
|
2017-03-15 04:55:22 +01:00
|
|
|
}
|
|
|
|
|
2020-05-02 07:35:33 +02:00
|
|
|
export default logger;
|