1 import type { Format
} from
'logform';
2 import { Logger
, createLogger
, format
, transport
} from
'winston';
3 import DailyRotateFile from
'winston-daily-rotate-file';
4 import TransportType from
'winston/lib/winston/transports/index.js';
6 import Configuration from
'./Configuration';
7 import Utils from
'./Utils';
9 let transports
: transport
[];
10 if (Configuration
.getLogRotate()) {
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 const logger
: Logger
= createLogger({
42 level
: Configuration
.getLogLevel(),
43 format
: format
.combine(format
.splat(), (format
[Configuration
.getLogFormat()] as () => Format
)()),
48 // If enabled, log to the `console` with the format:
49 // `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
51 if (Configuration
.getLogConsole()) {
53 new TransportType
.Console({
54 format
: format
.combine(
56 (format
[Configuration
.getLogFormat()] as () => Format
)()
62 export default logger
;