Skip to content
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

Modules using a variable binding to logger.log do not respect logger.setLevel #3524

Open
davidisaaclee opened this issue Jun 28, 2023 · 2 comments

Comments

@davidisaaclee
Copy link
Contributor

davidisaaclee commented Jun 28, 2023

Issue

I'm getting noisy logs from this library despite setting loglevel.getLogger("matrix").disableAll().

Cause

/* istanbul ignore next */
let debuglog: (...args: any[]) => void;
if (DEBUG) {
// using bind means that we get to keep useful line numbers in the console
debuglog = logger.log.bind(logger);
} else {
/* istanbul ignore next */
debuglog = function (): void {};
}

const debuglog = DEBUG ? logger.log.bind(logger) : function (): void {};

loglevel applies setLevel by replacing the relevant methods on the logger object: https://github.com/pimterry/loglevel/blob/f0187213feb6495630545a34a3b91633db47a1ee/lib/loglevel.js#L86-L97

If debuglog binds logger.log at the time of module load, debuglog will not be updated to respect setLevel. This causes noisy logs in my application even when running loglevel.getLogger("matrix").disableAll().

Possible fixes

  1. Use logger.log directly instead of debuglog. I don't understand why the library is disabling debuglog based on the local DEBUG constant, but I bet this could be achieved with loglevel's setLevel.
  2. Forfeit line numbers and use a reference to logger.log (e.g. const debuglog = (...args) => logger.log(...args))
  3. Some galaxy-brain Proxy implementation that I wasn't able to achieve (feel like there's a solution here that would keep the current DEBUG behavior and get line numbers with logs)

I've implemented option 1 in my branch: davidisaaclee@9849818

Please let me know if there's a better way to get these changes moving than filing Github issues – it seems like you have a lot on your plate, and I'd like to help in an effective way.

@vractal
Copy link

vractal commented Nov 1, 2023

have you tried logger.disableAll()? seems to work here

@davidisaaclee
Copy link
Contributor Author

@vractal I haven't, but that would prevent me from using my own logger instances, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants