-
-
Notifications
You must be signed in to change notification settings - Fork 331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move winston NodeJS transports to cli package #4509
Conversation
@@ -113,7 +113,7 @@ describe("chain / lightclient", function () { | |||
}); | |||
}).then(async (head) => { | |||
// Initialize lightclient | |||
loggerLC.important("Initializing lightclient", {slot: head.slot}); | |||
loggerLC.info("Initializing lightclient", {slot: head.slot}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.important API is not used anymore in production and forces creators of custom loggers to add it
@@ -70,49 +69,4 @@ describe("BlockArchiveRepository", function () { | |||
savedBlock2.message.slot = sampleBlock.message.slot; | |||
expect(ssz.phase0.SignedBeaconBlock.equals(savedBlock1, savedBlock2)).to.equal(true); | |||
}); | |||
|
|||
it("batchPutBinary should be faster than batchPut", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a test but a very old performance test with winston profiler. Removed as it's not even tracked
description: "Set log level for a specific module by name: 'chain=debug' or 'network=debug,chain=debug'", | ||
type: "array", | ||
string: true, | ||
coerce: (args: string[]) => args.map((item) => item.split(",")).flat(1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New option that allows to customize arbitrary modules without dedicated flags per module
datePattern: "YYYY-MM-DD", | ||
handleExceptions: true, | ||
maxFiles: args.logFileDailyRotate ?? defaultLogMaxFiles, | ||
auditFile: path.join(path.dirname(filename), ".log_rotate_audit.json"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For dockerized setups the audit file was placed in the process root and lost on restart. So DailyRotateFile could not clean the log files.
return this.levelByModule.delete(module); | ||
} | ||
|
||
_write(info: LogInfo, enc: BufferEncoding, callback: (error?: Error | null | undefined) => void): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit intrusive into Winston mechanics but this is the easiest solution to have custom module levels by far from the few options I've tried
@@ -60,7 +60,7 @@ describe("cmds / beacon / args handler", () => { | |||
fs.writeFileSync(peerIdFile, JSON.stringify(prevPeerId.toJSON())); | |||
|
|||
const {peerId} = await runBeaconHandlerInit({ | |||
peerIdFile, | |||
// peerIdFile, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is skipped, not sure why Typescript didn't complain about this one before
@@ -85,7 +85,7 @@ function humanReadableTemplateFn(_info: {[key: string]: any; level: string; mess | |||
|
|||
if (info.timestamp) str += info.timestamp; | |||
|
|||
str += `[${infoString.toUpperCase()}] ${info.level.padStart(infoPad)}: ${info.message}`; | |||
str += `[${infoString}] ${info.level.padStart(infoPad)}: ${info.message}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not mutate module field to keep it equal to what's there in the code
Performance Report✔️ no performance regression detected Full benchmark results
|
Tested locally with dev command and works well 👍
|
Motivation
@lodestar/utils
package is meant to contain misc utilities re-used across multiple packages that is platform agnostic, and compatible in the browser.Defining a common logger for all packages makes sense, but including a NodeJS only transport (FileRotate) breaks the above invariant.
Flags of type
--logger.chain.level debug
have been broken for a long time. This is due to the way winston handles log level at the transport level and doesn't allow customization on child logger.Description
Also, testing this change found out why file rotate does not clean old files. The library https://www.npmjs.com/package/winston-daily-rotate-file can only delete files that it know of if they are present in the audit file. The audit file location is by default the process cwd, which is not persisted if dockerized. Forcing the audit file to be in the same directory as the log file fixes the issue
lodestar/packages/cli/src/util/loggerTransports.ts
Line 38 in d6a7074
closes #2381