gancio-upstream/server/log.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

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')
const dayjs = require('dayjs')
const config = require('config')
2021-06-21 00:44:43 +02:00
const gancioFormat = format.printf(({ timestamp, level, message, error }) => {
2021-04-28 12:44:26 +02:00
return `${dayjs(timestamp).format('DD MMM YYYY HH:mm:ss')} ${level}: ${message}`
})
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
handleExceptions: true,
handleRejections: true,
level: 'debug',
2021-06-21 00:44:43 +02:00
format: format.combine(format.errors({ stack: true }), format.timestamp(), format.colorize(), format.splat(), gancioFormat)
2021-03-05 14:17:10 +01:00
}
)]
2021-04-28 12:44:26 +02:00
: [new DailyRotateFile({
handleExceptions: true,
handleRejections: true,
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-04-28 12:44:26 +02:00
format: format.combine(format.timestamp(), format.splat(), gancioFormat)
2021-06-19 22:53:01 +02:00
}),
new transports.Console(
{
handleExceptions: true,
handleRejections: true,
level: config.log_level || 'info',
format: format.combine(format.timestamp(), format.splat(), format.colorize(), gancioFormat)
}
)]
2021-03-05 14:17:10 +01:00
})
module.exports = logger