gancio-upstream/server/log.js

42 lines
1.3 KiB
JavaScript
Raw Permalink 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')
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(
{
level: config.log_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',
2023-12-29 17:47:50 +01:00
format: format.combine(format.splat(), format.timestamp(), gancioFormat)
2021-06-19 22:53:01 +02:00
}),
new transports.Console(
{
level: config.log_level || 'info',
2023-12-29 17:47:50 +01:00
format: format.combine(format.splat(), format.timestamp(), format.colorize(), gancioFormat)
2021-06-19 22:53:01 +02:00
}
)]
2021-03-05 14:17:10 +01:00
})
2021-09-30 11:15:21 +02:00
logger.info(`Logging to ${config.log_path}/gancio.log (level: ${config.log_level})`)
2021-03-05 14:17:10 +01:00
module.exports = logger