Files
sct-overseerr/server/logger.ts
2020-12-23 00:58:33 +09:00

41 lines
975 B
TypeScript

import * as winston from 'winston';
import path from 'path';
const hformat = winston.format.printf(
({ level, label, message, timestamp, ...metadata }) => {
let msg = `${timestamp} [${level}]${
label ? `[${label}]` : ''
}: ${message} `;
if (Object.keys(metadata).length > 0) {
msg += JSON.stringify(metadata);
}
return msg;
}
);
const logger = winston.createLogger({
level: process.env.LOG_LEVEL || 'debug',
format: winston.format.combine(
winston.format.splat(),
winston.format.timestamp(),
hformat
),
transports: [
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.splat(),
winston.format.timestamp(),
hformat
),
}),
new winston.transports.File({
filename: path.join(__dirname, '../config/logs/overseerr.log'),
maxsize: 20971520,
maxFiles: 6,
}),
],
});
export default logger;