1 import type { FormatWrap
} from
'logform';
2 import { createLogger
, format
, type transport
} from
'winston';
3 import TransportType from
'winston/lib/winston/transports/index.js';
4 import DailyRotateFile from
'winston-daily-rotate-file';
6 import { Configuration
} from
'./Configuration';
7 import { Utils
} from
'./Utils';
9 let transports
: transport
[];
10 if (Configuration
.getLogRotate() === true) {
11 const logMaxFiles
= Configuration
.getLogMaxFiles();
12 const logMaxSize
= Configuration
.getLogMaxSize();
15 filename
: Utils
.insertAt(
16 Configuration
.getLogErrorFile(),
18 Configuration
.getLogErrorFile()?.indexOf('.log')
21 ...(logMaxFiles
&& { maxFiles
: logMaxFiles
}),
22 ...(logMaxSize
&& { maxSize
: logMaxSize
}),
25 filename
: Utils
.insertAt(
26 Configuration
.getLogFile(),
28 Configuration
.getLogFile()?.indexOf('.log')
30 ...(logMaxFiles
&& { maxFiles
: logMaxFiles
}),
31 ...(logMaxSize
&& { maxSize
: logMaxSize
}),
36 new TransportType
.File({ filename
: Configuration
.getLogErrorFile(), level
: 'error' }),
37 new TransportType
.File({ filename
: Configuration
.getLogFile() }),
41 export const logger
= createLogger({
42 silent
: !Configuration
.getLogEnabled(),
43 level
: Configuration
.getLogLevel(),
44 format
: format
.combine(format
.splat(), (format
[Configuration
.getLogFormat()] as FormatWrap
)()),
49 // If enabled, log to the `console` with the format:
50 // `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
52 if (Configuration
.getLogConsole()) {
54 new TransportType
.Console({
55 format
: format
.combine(
57 (format
[Configuration
.getLogFormat()] as FormatWrap
)()