Skip to content

Commit

Permalink
fix(logger): restore previous --logFileDailyRotate behavior
Browse files Browse the repository at this point in the history
- `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
  • Loading branch information
nflaig committed Jun 1, 2023
1 parent e2e5417 commit 95996d2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/options/logOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const logOptions: CliCommandOptions<LogArgs> = {

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",
},
Expand Down
17 changes: 7 additions & 10 deletions packages/logger/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type LoggerNodeOpts = {
/**
* Rotation config for file output transport
*/
dailyRotate?: number;
dailyRotate: number;
};
/**
* Module prefix for all logs
Expand Down Expand Up @@ -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` -> 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
const enableDailyRotate = 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.
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/test/unit/loggerTransport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 95996d2

Please sign in to comment.