chore: switch coding style to JS standard
[e-mobility-charging-stations-simulator.git] / src / utils / Logger.ts
index ba5fe9eb74da13ea0bb8ecb1350a9f3426235125..7d80e1aece51349349abd0766f8af5ae2b196833 100644 (file)
@@ -1,69 +1,74 @@
-import type { FormatWrap } from 'logform';
-import { createLogger, format, type transport } from 'winston';
-import TransportType from 'winston/lib/winston/transports/index.js';
-import DailyRotateFile from 'winston-daily-rotate-file';
+import type { FormatWrap } from 'logform'
+import { createLogger, format, type transport } from 'winston'
+import TransportType from 'winston/lib/winston/transports/index.js'
+import DailyRotateFile from 'winston-daily-rotate-file'
 
-import { Configuration } from './Configuration.js';
-import { insertAt } from './Utils.js';
-import { ConfigurationSection, type LogConfiguration } from '../types/index.js';
+import { Configuration } from './Configuration.js'
+import { insertAt } from './Utils.js'
+import { ConfigurationSection, type LogConfiguration } from '../types/index.js'
 
 const logConfiguration = Configuration.getConfigurationSection<LogConfiguration>(
-  ConfigurationSection.log,
-);
-let transports: transport[];
+  ConfigurationSection.log
+)
+let transports: transport[]
 if (logConfiguration.rotate === true) {
-  const logMaxFiles = logConfiguration.maxFiles;
-  const logMaxSize = logConfiguration.maxSize;
+  const logMaxFiles = logConfiguration.maxFiles
+  const logMaxSize = logConfiguration.maxSize
   transports = [
     new DailyRotateFile({
       filename: insertAt(
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
         logConfiguration.errorFile!,
         '-%DATE%',
-        logConfiguration.errorFile!.indexOf('.log'),
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        logConfiguration.errorFile!.indexOf('.log')
       ),
       level: 'error',
-      ...(logMaxFiles && { maxFiles: logMaxFiles }),
-      ...(logMaxSize && { maxSize: logMaxSize }),
+      ...(logMaxFiles != null && { maxFiles: logMaxFiles }),
+      ...(logMaxSize != null && { maxSize: logMaxSize })
     }),
     new DailyRotateFile({
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       filename: insertAt(logConfiguration.file!, '-%DATE%', logConfiguration.file!.indexOf('.log')),
-      ...(logMaxFiles && { maxFiles: logMaxFiles }),
-      ...(logMaxSize && { maxSize: logMaxSize }),
-    }),
-  ];
+      ...(logMaxFiles != null && { maxFiles: logMaxFiles }),
+      ...(logMaxSize != null && { maxSize: logMaxSize })
+    })
+  ]
 } else {
   transports = [
     new TransportType.File({
       filename: logConfiguration.errorFile,
-      level: 'error',
+      level: 'error'
     }),
     new TransportType.File({
-      filename: logConfiguration.file,
-    }),
-  ];
+      filename: logConfiguration.file
+    })
+  ]
 }
 
 export const logger = createLogger({
-  silent: !logConfiguration.enabled,
+  silent: logConfiguration.enabled === false,
   level: logConfiguration.level,
   format: format.combine(
     format.splat(),
-    (format[logConfiguration.format! as keyof FormatWrap] as FormatWrap)(),
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    (format[logConfiguration.format! as keyof FormatWrap] as FormatWrap)()
   ),
-  transports,
-});
+  transports
+})
 
 //
 // If enabled, log to the `console` with the format:
 // `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
 //
-if (logConfiguration.console) {
+if (logConfiguration.console === true) {
   logger.add(
     new TransportType.Console({
       format: format.combine(
         format.splat(),
-        (format[logConfiguration.format! as keyof FormatWrap] as FormatWrap)(),
-      ),
-    }),
-  );
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        (format[logConfiguration.format! as keyof FormatWrap] as FormatWrap)()
+      )
+    })
+  )
 }