Commit | Line | Data |
---|---|---|
7ec46a9a JB |
1 | import 'winston-daily-rotate-file'; |
2 | ||
6af9012e | 3 | import Configuration from './Configuration'; |
7ec46a9a JB |
4 | import Utils from './Utils'; |
5 | import winston from 'winston'; | |
6 | ||
7 | const maxLogFiles = 7; | |
7dde0b73 | 8 | |
7ec46a9a | 9 | const logger = winston.createLogger({ |
2e6f5966 | 10 | level: Configuration.getLogLevel(), |
7ec46a9a | 11 | format: winston.format.combine(winston.format.splat(), winston.format[Configuration.getLogFormat()]()), |
7dde0b73 JB |
12 | transports: [ |
13 | // | |
14 | // - Write to all logs with level `info` and below to `combined.log` | |
15 | // - Write all logs error (and below) to `error.log`. | |
16 | // | |
7ec46a9a JB |
17 | new winston.transports.DailyRotateFile({ filename: Utils.insertAt(Configuration.getLogErrorFile(), '-%DATE%', Configuration.getLogErrorFile().indexOf('.log')), level: 'error', maxFiles: maxLogFiles }), |
18 | new winston.transports.DailyRotateFile({ filename: Utils.insertAt(Configuration.getLogFile(), '-%DATE%', Configuration.getLogFile().indexOf('.log')), maxFiles: maxLogFiles }), | |
7dde0b73 JB |
19 | ], |
20 | }); | |
21 | ||
22 | // | |
23 | // If enabled, log to the `console` with the format: | |
24 | // `${info.level}: ${info.message} JSON.stringify({ ...rest }) ` | |
25 | // | |
7ec46a9a JB |
26 | if (Configuration.getLogConsole()) { |
27 | logger.add(new winston.transports.Console({ | |
28 | format: winston.format.combine(winston.format.splat(), winston.format[Configuration.getLogFormat()]()), | |
7dde0b73 JB |
29 | })); |
30 | } | |
31 | ||
3f40bc9c | 32 | export default logger; |