Command-fix/src/logging.ts

37 lines
891 B
TypeScript
Raw Normal View History

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
});
// 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');
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({
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
}));
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;