@@ -7,6 +7,10 @@ import type { AppConfig } from './config.js';
|
||||
|
||||
const LOG_RETENTION_DAYS = 7;
|
||||
|
||||
function shouldUseTransport(config: AppConfig) {
|
||||
return config.nodeEnv !== 'test' && config.logLevel !== 'silent';
|
||||
}
|
||||
|
||||
function cleanupExpiredLogs(logsDir: string) {
|
||||
if (!fs.existsSync(logsDir)) {
|
||||
return;
|
||||
@@ -28,6 +32,14 @@ function cleanupExpiredLogs(logsDir: string) {
|
||||
}
|
||||
|
||||
export function createLogger(config: AppConfig): Logger {
|
||||
if (!shouldUseTransport(config)) {
|
||||
return pino({
|
||||
level: config.logLevel,
|
||||
timestamp: pino.stdTimeFunctions.isoTime,
|
||||
base: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
fs.mkdirSync(config.logsDir, { recursive: true });
|
||||
cleanupExpiredLogs(config.logsDir);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user