1 import type { FormatWrap
} from
'logform';
2 import { type Logger
, createLogger
, format
, type transport
} from
'winston';
3 import TransportType from
'winston/lib/winston/transports';
4 import DailyRotateFile from
'winston-daily-rotate-file';
6 import { Configuration
, Utils
} from
'./internal';
8 let transports
: transport
[];
9 if (Configuration
.getLogRotate() === true) {
10 const logMaxFiles
= Configuration
.getLogMaxFiles();
11 const logMaxSize
= Configuration
.getLogMaxSize();
14 filename
: Utils
.insertAt(
15 Configuration
.getLogErrorFile(),
17 Configuration
.getLogErrorFile()?.indexOf('.log')
20 ...(logMaxFiles
&& { maxFiles
: logMaxFiles
}),
21 ...(logMaxSize
&& { maxSize
: logMaxSize
}),
24 filename
: Utils
.insertAt(
25 Configuration
.getLogFile(),
27 Configuration
.getLogFile()?.indexOf('.log')
29 ...(logMaxFiles
&& { maxFiles
: logMaxFiles
}),
30 ...(logMaxSize
&& { maxSize
: logMaxSize
}),
35 new TransportType
.File({ filename
: Configuration
.getLogErrorFile(), level
: 'error' }),
36 new TransportType
.File({ filename
: Configuration
.getLogFile() }),
40 const logger
: Logger
= createLogger({
41 level
: Configuration
.getLogLevel(),
42 format
: format
.combine(format
.splat(), (format
[Configuration
.getLogFormat()] as FormatWrap
)()),
47 // If enabled, log to the `console` with the format:
48 // `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
50 if (Configuration
.getLogConsole()) {
52 new TransportType
.Console({
53 format
: format
.combine(
55 (format
[Configuration
.getLogFormat()] as FormatWrap
)()