From: Jérôme Benoit Date: Fri, 23 Dec 2022 13:44:43 +0000 (+0100) Subject: Add configuration directive for the maximum log files size X-Git-Tag: v1.1.89~62 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9988696df26aba9c34733f9093ebf3d957ba9d02;p=e-mobility-charging-stations-simulator.git Add configuration directive for the maximum log files size Signed-off-by: Jérôme Benoit --- diff --git a/src/types/ConfigurationData.ts b/src/types/ConfigurationData.ts index 58372a38..8ab9bcfd 100644 --- a/src/types/ConfigurationData.ts +++ b/src/types/ConfigurationData.ts @@ -73,7 +73,8 @@ export type ConfigurationData = { logFormat?: string; logLevel?: string; logRotate?: boolean; - logMaxFiles?: number; + logMaxFiles?: number | string; + logMaxSize?: number | string; logFile?: string; logErrorFile?: string; logConsole?: boolean; diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index f1893531..c17cad01 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -246,10 +246,18 @@ export default class Configuration { : true; } - static getLogMaxFiles(): number { - return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logMaxFiles') - ? Configuration.getConfig().logMaxFiles - : 7; + static getLogMaxFiles(): number | string | undefined { + return ( + Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logMaxFiles') && + Configuration.getConfig().logMaxFiles + ); + } + + static getLogMaxSize(): number | string | undefined { + return ( + Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logMaxFiles') && + Configuration.getConfig().logMaxSize + ); } static getLogLevel(): string { diff --git a/src/utils/Logger.ts b/src/utils/Logger.ts index 95d5347d..61e4b0bc 100644 --- a/src/utils/Logger.ts +++ b/src/utils/Logger.ts @@ -9,6 +9,7 @@ import Utils from './Utils'; let transports: transport[]; if (Configuration.getLogRotate()) { const logMaxFiles = Configuration.getLogMaxFiles(); + const logMaxSize = Configuration.getLogMaxSize(); transports = [ new DailyRotateFile({ filename: Utils.insertAt( @@ -17,7 +18,8 @@ if (Configuration.getLogRotate()) { Configuration.getLogErrorFile().indexOf('.log') ), level: 'error', - maxFiles: logMaxFiles, + ...(logMaxFiles && { maxFiles: logMaxFiles }), + ...(logMaxSize && { maxSize: logMaxSize }), }), new DailyRotateFile({ filename: Utils.insertAt( @@ -25,7 +27,8 @@ if (Configuration.getLogRotate()) { '-%DATE%', Configuration.getLogFile().indexOf('.log') ), - maxFiles: logMaxFiles, + ...(logMaxFiles && { maxFiles: logMaxFiles }), + ...(logMaxSize && { maxSize: logMaxSize }), }), ]; } else {