Simplify DC current output type handling.
[e-mobility-charging-stations-simulator.git] / src / utils / Logger.js
1 import Configuration from './Configuration.js';
2 import Winston from 'winston';
3
4 const logger = Winston.createLogger({
5 level: Configuration.getLogLevel(),
6 format: Winston.format.combine(Winston.format.splat(), Winston.format[Configuration.getLogFormat()]()),
7 transports: [
8 //
9 // - Write to all logs with level `info` and below to `combined.log`
10 // - Write all logs error (and below) to `error.log`.
11 //
12 new Winston.transports.File({filename: Configuration.getErrorFile(), level: 'error'}),
13 new Winston.transports.File({filename: Configuration.getLogFile()}),
14 ],
15 });
16
17 //
18 // If enabled, log to the `console` with the format:
19 // `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
20 //
21 if (Configuration.getConsoleLog()) {
22 logger.add(new Winston.transports.Console({
23 format: Winston.format.combine(Winston.format.splat(), Winston.format[Configuration.getLogFormat()]()),
24 }));
25 }
26
27 export default logger;