Skip to content

Make logger usage optional #3967

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

Merged
merged 9 commits into from
Apr 17, 2025
Merged

Make logger usage optional #3967

merged 9 commits into from
Apr 17, 2025

Conversation

scorbajio
Copy link
Contributor

@scorbajio scorbajio commented Apr 9, 2025

This change makes the logger optional in the client package by using the optional chaining operator and also introduces a new option for the cli logLevel option to be set to off if the logger is to be turned off:

npm run client:start:dev2 -- --logLevel=off

Copy link

codecov bot commented Apr 9, 2025

Codecov Report

Attention: Patch coverage is 30.79848% with 182 lines in your changes missing coverage. Please review.

Project coverage is 79.56%. Comparing base (3f0cd29) to head (a88a082).
Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 83.34% <ø> (ø)
blockchain 89.32% <ø> (ø)
client 67.94% <30.79%> (-0.54%) ⬇️
common 97.51% <ø> (ø)
devp2p 86.78% <ø> (ø)
evm 72.98% <ø> (ø)
genesis 99.98% <ø> (ø)
mpt 89.76% <ø> (ø)
rlp 91.43% <ø> (ø)
statemanager 69.16% <ø> (ø)
tx 90.59% <ø> (ø)
util 81.87% <ø> (ø)
vm 57.20% <ø> (ø)
wallet 88.55% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

holgerd77
holgerd77 previously approved these changes Apr 14, 2025
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Great start and great PR, looks good! 🤩

I've addressed some nits with the console.log output (we should not do in this case).

Can you eventually directly do a follow up PR where we get rid now of these ugly logger messages in the client integration tests (so: npm run test:integration)? That would be super great! 🤩 We actually wanted to do this in the first place when we added these tests long ago, but weren't able to do so since the logger was not optional yet.

Didn't have such a close look, but I would guess that these chain.config.logger!.silent = true lines might now also be able to replaced? Core thing though is that the logger for most tests is just generally turned off.

for (const transport of (replServer.context.client as EthereumClient).config.logger
const logger = (replServer.context.client as EthereumClient).config.logger
if (logger === undefined) {
this.displayPrompt()
Copy link
Member

Choose a reason for hiding this comment

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

Some nit: I understand the intention, but if the logger is turned off, we should not use the (a) logger at all, not even the console.log() logger and if it's only for informing the user. Have removed and directly pushed.

args: { [key: string]: any } = { logLevel: 'info' },
): WinstonLogger | undefined {
if (args.logLevel === 'off') {
console.log('logger turned off')
Copy link
Member

Choose a reason for hiding this comment

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

Also here, will temporarily deactivate the associated test case.

holgerd77
holgerd77 previously approved these changes Apr 14, 2025
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Another LGTM

@acolytec3 acolytec3 force-pushed the make-logger-optional branch 2 times, most recently from cad20ce to a4e409f Compare April 16, 2025 01:01
}
}
await clientRunHelper(cliArgs, onData)
}, 30000)*/
Copy link
Member

Choose a reason for hiding this comment

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

Note: this is a newly added test, but this is commented out. The reason is that the tests in this file test stuff by by listening to whatever the output (what is being logged 😅 ) is. Since this test expects no output, we thus cannot test this, this way.

As a general comment: the way to test these things (like in this file) by listening to comments (and also listening to hardcoded strings, not strings which we read from some file, is not the way to test it. If we change a logging message, we could break a test here because the test expects a certain string.

I think the way to test the CLI like this, and also how the CLI is set up to be tested, is not good. I will open an issue for this.

Copy link
Member

Choose a reason for hiding this comment

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

I created this issue: #3983

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@holgerd77 holgerd77 merged commit 9ee0c91 into master Apr 17, 2025
40 of 41 checks passed
@holgerd77 holgerd77 deleted the make-logger-optional branch April 17, 2025 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants