pimterry / loglevel

:ledger: Minimal lightweight logging for JavaScript, adding reliable log level methods to wrap any available console.log methods

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reference change in log.debug?

KonradHoeffner opened this issue · comments

We want to encapsulate log.debug with additional functionality, but for the reference seems to change, which breaks our code:

const ref = log.debug;
console.log(ref===log.debug); // true
log.debug("Hello World");
// some more logging
console.log(ref===log.debug); // false

Is this intended functionality and a wrong assumption to make that the reference stays the same? Or must there be some other issue in our code?

We are using loglevel 1.6.1 in the browser.

Can you put together a standalone reproduction so I can see this in action? It'd also be useful if you could be more specific about which browser you're using when you see this - a https://www.whatsmybrowser.org/ link would be perfect.

For now, using just the code above I can't seem to reproduce this. Skimming the code, the only time that calling log.debug would ever change the definition of log.debug is if console wasn't defined initially. That's designed to handle issues in IE (either old IE, or newer IE with compatibility modes set badly), and if you're not using IE I don't think this should ever happen.

One way you could see this effect is if you're calling setLevel between the two checks. Calling setLevel does redefine every log method, either creating it afresh or replacing it with a no-op, depending on the level selected.

The browser is Firefox 67, the link is www.whatsmybrowser.org/b/S9N79PS. We do indeed use setLevel, I will investigate whether this solves the problem.

Yes, setLevel was indeed the problem, that solved it, thanks!

Great to hear, glad I could help! 👍