-
-
Notifications
You must be signed in to change notification settings - Fork 291
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
feat!: worker friendly logger instances #5490
Conversation
Performance Report✔️ no performance regression detected Full benchmark results
|
packages/logger/package.json
Outdated
"exports": { | ||
".": { | ||
"import": "./lib/index.js" | ||
}, | ||
"./browser": { | ||
"import": "./lib/loggers/browser.js" | ||
}, | ||
"./node": { | ||
"import": "./lib/loggers/node.js" | ||
}, | ||
"./empty": { | ||
"import": "./lib/loggers/empty.js" | ||
} | ||
}, |
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.
Instead of subpath exports why not not use conditional exports https://nodejs.org/api/packages.html#conditional-exports. And only default export. This way user can use a consistent import pattern.
"exports": {
".": {
"node": "./lib/loggers/node.js",
"browser": "./lib/loggers/browser.js",
"default": "./lib/index.js"
},
},
// Return a new logger instance with different module and log level | ||
// but a reference to the same transports, such that there's only one | ||
// transport instance per tree of child loggers | ||
child(opts: LoggerNodeChildOpts): LoggerNode { |
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.
@dapplion This changed how we create child loggers, it creates a new event listener for each child logger
Was the previous implementation not compatible when using workers?
child(options: LoggerChildOpts): WinstonLogger { |
Using native winston.child
does not work as mention in previous comment.
Workaround for now is to just increase max listeners which should be fine to do as explained in the PR
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.
Hmm unsure of the reason forgot to document, so may be an oversight. Could you test if the previous approach works fine still?
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.
Child loggers are only created in the main thread, does not affect workers at all because we initialize a completely new logger instance there
const logger = getNodeLogger(workerData.loggerOpts); |
Opened a PR to revert logger.child
implementation back to original approach
const filename = opts.file.filepath; | ||
|
||
transports.push( | ||
opts.file.dailyRotate != null |
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.
What's the expected approach to disable log file rotation now?
The comment above does not longer match behavior as setting --logFileDailyRotate 0
will still initialize DailyRotateFile
. Default winston.transports.File
is effectively never used now.
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.
Right, logFileDailyRotate is a bit a weird UX flag. Does yargs support accepting both syntax with no arg --logFileDailyRotate
and with arg --logFileDailyRotate 5
? That would make handling easier
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.
Both works, but setting --logFileDailyRotate
(without value) and omitting the flag will result in 5
due to the fact that we set it as default here
default: 5, |
Setting it to 0
to disable daily file rotation seems logical to me (and is most explicit), that's also how it worked previously
🎉 This PR is included in v1.9.0 🎉 |
Motivation
Our current Logger instances are not DX friendly to support workers.
Let's list the requirements:
@lodestar/light-client
or@lodestar/reqresp
just want access to a generic simple Logger instance to write data at some LogLevel. No need to expose them to more complicated loggers or to force dependencies on NodeJS specific code@lodestar/beacon-node
need access to a generic logger with more features, specifically:2.1. Create child logger with custom settings, which must re-use references to the same transport instances
2.2. Serialize a logger instance settings and transport settings for a worker downstream
@lodestar/cli
has to be able to produce compatible logger instances for the above casesDescription
So to fulfill 1. and 2. there must exist separate insterfaces, which are:
Logger
LoggerNode
LoggerNode
can export its settings withtoOpts()
and be recreate with those