Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 6 additions & 9 deletions packages/logger/src/node.ts
Original file line number Diff line number Diff line change
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` -> 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.
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}});

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO better to set dailyRotate here to use DailyRotateFile which is the more commonly used file transport


stdoutHook = hookProcessStdout();

Expand Down