-const logger = Winston.createLogger({
- level: Configuration.getLogLevel(),
- format: Winston.format.combine(Winston.format.splat(), Winston.format[Configuration.getLogFormat()]()),
- transports: [
- //
- // - Write to all logs with level `info` and below to `combined.log`
- // - Write all logs error (and below) to `error.log`.
- //
- new Winston.transports.File({ filename: Configuration.getErrorFile(), level: 'error' }),
- new Winston.transports.File({ filename: Configuration.getLogFile() }),
- ],
+import { Configuration } from './Configuration';
+import { insertAt } from './Utils';
+import { ConfigurationSection, type LogConfiguration } from '../types';
+
+const logConfiguration = Configuration.getConfigurationSection<LogConfiguration>(
+ ConfigurationSection.log,
+);
+let transports: transport[];
+if (logConfiguration.rotate === true) {
+ const logMaxFiles = logConfiguration.maxFiles;
+ const logMaxSize = logConfiguration.maxSize;
+ transports = [
+ new DailyRotateFile({
+ filename: insertAt(
+ logConfiguration.errorFile!,
+ '-%DATE%',
+ logConfiguration.errorFile!.indexOf('.log'),
+ ),
+ level: 'error',
+ ...(logMaxFiles && { maxFiles: logMaxFiles }),
+ ...(logMaxSize && { maxSize: logMaxSize }),
+ }),
+ new DailyRotateFile({
+ filename: insertAt(logConfiguration.file!, '-%DATE%', logConfiguration.file!.indexOf('.log')),
+ ...(logMaxFiles && { maxFiles: logMaxFiles }),
+ ...(logMaxSize && { maxSize: logMaxSize }),
+ }),
+ ];
+} else {
+ transports = [
+ new TransportType.File({
+ filename: logConfiguration.errorFile,
+ level: 'error',
+ }),
+ new TransportType.File({
+ filename: logConfiguration.file,
+ }),
+ ];
+}
+
+export const logger = createLogger({
+ silent: !logConfiguration.enabled,
+ level: logConfiguration.level,
+ format: format.combine(
+ format.splat(),
+ (format[logConfiguration.format! as keyof FormatWrap] as FormatWrap)(),
+ ),
+ transports,