mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2025-12-24 02:39:18 -05:00
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import path from 'path';
|
|
import * as winston from 'winston';
|
|
import 'winston-daily-rotate-file';
|
|
|
|
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?.toLowerCase() || '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.DailyRotateFile({
|
|
filename: process.env.CONFIG_DIRECTORY
|
|
? `${process.env.CONFIG_DIRECTORY}/logs/seerr-%DATE%.log`
|
|
: path.join(__dirname, '../config/logs/seerr-%DATE%.log'),
|
|
datePattern: 'YYYY-MM-DD',
|
|
zippedArchive: true,
|
|
maxSize: '20m',
|
|
maxFiles: '7d',
|
|
createSymlink: true,
|
|
symlinkName: 'seerr.log',
|
|
}),
|
|
new winston.transports.DailyRotateFile({
|
|
filename: process.env.CONFIG_DIRECTORY
|
|
? `${process.env.CONFIG_DIRECTORY}/logs/.machinelogs-%DATE%.json`
|
|
: path.join(__dirname, '../config/logs/.machinelogs-%DATE%.json'),
|
|
datePattern: 'YYYY-MM-DD',
|
|
zippedArchive: true,
|
|
maxSize: '20m',
|
|
maxFiles: '1d',
|
|
createSymlink: true,
|
|
symlinkName: '.machinelogs.json',
|
|
format: winston.format.combine(
|
|
winston.format.splat(),
|
|
winston.format.timestamp(),
|
|
winston.format.json()
|
|
),
|
|
}),
|
|
],
|
|
});
|
|
|
|
export default logger;
|