diff --git a/packages/cli/src/options/logOptions.ts b/packages/cli/src/options/logOptions.ts index adabd8c0cdfa..6eaad79611d9 100644 --- a/packages/cli/src/options/logOptions.ts +++ b/packages/cli/src/options/logOptions.ts @@ -36,7 +36,7 @@ export const logOptions: CliCommandOptions = { logFileDailyRotate: { description: - "Daily rotate log files, set to an integer to limit the file count, set to 0(zero) to disable rotation", + "Daily rotate log files, set to an integer to limit the file count, set to 0 (zero) to disable rotation", default: 5, type: "number", }, diff --git a/packages/logger/src/node.ts b/packages/logger/src/node.ts index 5b5bd97c4d0d..11918e437376 100644 --- a/packages/logger/src/node.ts +++ b/packages/logger/src/node.ts @@ -90,19 +90,16 @@ function getNodeLoggerTransports(opts: LoggerNodeOpts): winston.transport[] { const transports: TransportStream[] = [consoleTransport]; - // yargs populates with undefined if just set but with no arg - // $ ./bin/lodestar.js beacon --logFileDailyRotate - // args = { - // logFileDailyRotate: undefined, - // } - // `lodestar --logFileDailyRotate` -> enabled daily rotate with default value - // `lodestar --logFileDailyRotate 10` -> set daily rotate to custom value 10 - // `lodestar --logFileDailyRotate 0` -> disable daily rotate and accumulate in same file if (opts.file) { const filename = opts.file.filepath; + // `lodestar --logFileDailyRotate` -> enable daily rotate with default value + // `lodestar --logFileDailyRotate 10` -> set daily rotate to custom value 10 + // `lodestar --logFileDailyRotate 0` -> disable daily rotate and accumulate in same file + const enableDailyRotate = opts.file.dailyRotate != null && opts.file.dailyRotate > 0; + transports.push( - opts.file.dailyRotate != null + enableDailyRotate ? new DailyRotateFile({ level: opts.file.level, //insert the date pattern in filename before the file extension. diff --git a/packages/logger/test/unit/loggerTransport.test.ts b/packages/logger/test/unit/loggerTransport.test.ts index 255e804dd2b0..d7d1120d9235 100644 --- a/packages/logger/test/unit/loggerTransport.test.ts +++ b/packages/logger/test/unit/loggerTransport.test.ts @@ -127,7 +127,7 @@ describe("winston transport log to file", () => { const filenameRx = /^child-logger-test/; const filepath = path.join(tmpDir, filename); - const logger = getNodeLoggerTest({module: "a", file: {filepath, level: LogLevel.info}}); + const logger = getNodeLoggerTest({module: "a", file: {filepath, level: LogLevel.info, dailyRotate: 5}}); stdoutHook = hookProcessStdout();