3f94e63eb77f546cd33ad1be53771955092645b5
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 { insertAt
} from
'./Utils';
9 let transports
: transport
[];
10 if (Configuration
.getLog().rotate
=== true) {
11 const logMaxFiles
= Configuration
.getLog().maxFiles
;
12 const logMaxSize
= Configuration
.getLog().maxSize
;
16 Configuration
.getLog().errorFile
,
18 Configuration
.getLog().errorFile
?.indexOf('.log')
21 ...(logMaxFiles
&& { maxFiles
: logMaxFiles
}),
22 ...(logMaxSize
&& { maxSize
: logMaxSize
}),
26 Configuration
.getLog().file
,
28 Configuration
.getLog().file
?.indexOf('.log')
30 ...(logMaxFiles
&& { maxFiles
: logMaxFiles
}),
31 ...(logMaxSize
&& { maxSize
: logMaxSize
}),
36 new TransportType
.File({ filename
: Configuration
.getLog().errorFile
, level
: 'error' }),
37 new TransportType
.File({ filename
: Configuration
.getLog().file
}),
41 export const logger
= createLogger({
42 silent
: !Configuration
.getLog().enabled
,
43 level
: Configuration
.getLog().level
,
44 format
: format
.combine(format
.splat(), (format
[Configuration
.getLog().format
] as FormatWrap
)()),
49 // If enabled, log to the `console` with the format:
50 // `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
52 if (Configuration
.getLog().console
) {
54 new TransportType
.Console({
55 format
: format
.combine(
57 (format
[Configuration
.getLog().format
] as FormatWrap
)()