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