2021-03-05 14:17:10 +01:00
|
|
|
const { createLogger, transports, format } = require('winston')
|
2021-04-28 12:44:26 +02:00
|
|
|
const DailyRotateFile = require('winston-daily-rotate-file')
|
2021-09-27 10:42:17 +02:00
|
|
|
const config = require('./config')
|
2021-04-28 12:44:26 +02:00
|
|
|
|
2021-07-08 20:41:56 +02:00
|
|
|
const gancioFormat = format.printf(info => {
|
|
|
|
if (info.stack) {
|
|
|
|
return `${info.timestamp} ${info.level}: ${info.message} \r\n${info.stack}`
|
|
|
|
} else {
|
|
|
|
return `${info.timestamp} ${info.level}: ${info.message}`
|
|
|
|
}
|
2021-04-28 12:44:26 +02:00
|
|
|
})
|
2021-03-05 14:17:10 +01:00
|
|
|
|
|
|
|
const logger = createLogger({
|
2021-04-28 12:44:26 +02:00
|
|
|
exitOnError: false,
|
2021-03-05 14:17:10 +01:00
|
|
|
transports: process.env.NODE_ENV !== 'production'
|
|
|
|
? [new transports.Console(
|
|
|
|
{
|
2021-04-28 12:44:26 +02:00
|
|
|
level: 'debug',
|
2021-07-08 20:41:56 +02:00
|
|
|
format: format.combine(format.splat(), format.timestamp(), format.colorize(), gancioFormat)
|
2021-03-05 14:17:10 +01:00
|
|
|
}
|
|
|
|
)]
|
2021-04-28 12:44:26 +02:00
|
|
|
: [new DailyRotateFile({
|
2021-05-27 00:04:10 +02:00
|
|
|
level: config.log_level || 'info',
|
|
|
|
filename: config.log_path + '/gancio.%DATE%.log',
|
2021-04-28 12:44:26 +02:00
|
|
|
symlinkName: 'gancio.log',
|
|
|
|
createSymlink: true,
|
|
|
|
zippedArchive: true,
|
|
|
|
maxSize: '10m',
|
2021-06-19 22:53:01 +02:00
|
|
|
maxFiles: '10d',
|
2021-07-08 20:41:56 +02:00
|
|
|
format: format.combine(format.timestamp(), gancioFormat)
|
2021-06-19 22:53:01 +02:00
|
|
|
}),
|
|
|
|
new transports.Console(
|
|
|
|
{
|
|
|
|
level: config.log_level || 'info',
|
2021-07-08 20:41:56 +02:00
|
|
|
format: format.combine(format.timestamp(), format.colorize(), gancioFormat)
|
2021-06-19 22:53:01 +02:00
|
|
|
}
|
|
|
|
)]
|
2021-03-05 14:17:10 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = logger
|