Initial portage to TypeScript.
[e-mobility-charging-stations-simulator.git] / src / utils / Logger.ts
CommitLineData
6af9012e 1import Configuration from './Configuration';
3f40bc9c 2import Winston from 'winston';
7dde0b73
JB
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 //
6af9012e
JB
12 new Winston.transports.File({ filename: Configuration.getErrorFile(), level: 'error' }),
13 new Winston.transports.File({ filename: Configuration.getLogFile() }),
7dde0b73
JB
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
3f40bc9c 27export default logger;