From: Jérôme Benoit Date: Sat, 13 Feb 2021 18:05:42 +0000 (+0100) Subject: Logger.ts: import cleanups X-Git-Tag: v1.0.1-0~104^2~8 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8387cd3144acc55a2eaa20d8cf26745a4456f9d8;p=e-mobility-charging-stations-simulator.git Logger.ts: import cleanups Signed-off-by: Jérôme Benoit --- diff --git a/src/utils/Logger.ts b/src/utils/Logger.ts index dfd04e90..ccbc63ca 100644 --- a/src/utils/Logger.ts +++ b/src/utils/Logger.ts @@ -1,27 +1,27 @@ -import 'winston-daily-rotate-file'; - -import winston, { transport } from 'winston'; +import { Console, File } from 'winston/lib/winston/transports'; +import { Logger, createLogger, format, transport } from 'winston'; import Configuration from './Configuration'; +import DailyRotateFile from 'winston-daily-rotate-file'; import Utils from './Utils'; let transports: transport[]; if (Configuration.getLogRotate()) { const logMaxFiles = Configuration.getLogMaxFiles(); transports = [ - new winston.transports.DailyRotateFile({ filename: Utils.insertAt(Configuration.getLogErrorFile(), '-%DATE%', Configuration.getLogErrorFile().indexOf('.log')), level: 'error', maxFiles: logMaxFiles }), - new winston.transports.DailyRotateFile({ filename: Utils.insertAt(Configuration.getLogFile(), '-%DATE%', Configuration.getLogFile().indexOf('.log')), maxFiles: logMaxFiles }), + new DailyRotateFile({ filename: Utils.insertAt(Configuration.getLogErrorFile(), '-%DATE%', Configuration.getLogErrorFile().indexOf('.log')), level: 'error', maxFiles: logMaxFiles }), + new DailyRotateFile({ filename: Utils.insertAt(Configuration.getLogFile(), '-%DATE%', Configuration.getLogFile().indexOf('.log')), maxFiles: logMaxFiles }), ]; } else { transports = [ - new winston.transports.File({ filename: Configuration.getLogErrorFile(), level: 'error' }), - new winston.transports.File({ filename: Configuration.getLogFile() }), + new File({ filename: Configuration.getLogErrorFile(), level: 'error' }), + new File({ filename: Configuration.getLogFile() }), ]; } -const logger = winston.createLogger({ +const logger: Logger = createLogger({ level: Configuration.getLogLevel(), - format: winston.format.combine(winston.format.splat(), winston.format[Configuration.getLogFormat()]()), + format: format.combine(format.splat(), format[Configuration.getLogFormat()]()), transports: transports, }); @@ -30,8 +30,8 @@ const logger = winston.createLogger({ // `${info.level}: ${info.message} JSON.stringify({ ...rest }) ` // if (Configuration.getLogConsole()) { - logger.add(new winston.transports.Console({ - format: winston.format.combine(winston.format.splat(), winston.format[Configuration.getLogFormat()]()), + logger.add(new Console({ + format: format.combine(format.splat(), format[Configuration.getLogFormat()]()), })); }