Improve logging.
[e-mobility-charging-stations-simulator.git] / src / utils / Logger.js
CommitLineData
7dde0b73
JB
1const Configuration = require('./Configuration');
2const Winston = require('winston');
3
4const logger = Winston.createLogger({
2e6f5966 5 level: Configuration.getLogLevel(),
027b409a 6 format: Winston.format.combine(Winston.format.splat(), Winston.format[Configuration.getLogFormat()]()),
7dde0b73
JB
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//
21if (Configuration.getConsoleLog()) {
22 logger.add(new Winston.transports.Console({
027b409a 23 format: Winston.format.combine(Winston.format.splat(), Winston.format[Configuration.getLogFormat()]()),
7dde0b73
JB
24 }));
25}
26
27module.exports = logger;