pimterry / loglevel

:ledger: Minimal lightweight logging for JavaScript, adding reliable log level methods to wrap any available console.log methods
MIT License
2.62k stars 157 forks source link

log is not defined when attempting setLevel() in console #163

Closed nboxall1 closed 3 years ago

nboxall1 commented 3 years ago

Apologies, this is more of a question than a bug report. In the documentation it says "...then run log.setLevel("trace") in your console to turn it all back on...". I'm using Chrome on a Mac. When I enter log.setLevel("trace") in the dev tools console for an app I am developing with has imported loglevel as log i'm getting "Uncaught ReferenceError: log is not defined". I'm obviously missing something here so any tips would be greatly appreciated.

pimterry commented 3 years ago

It sounds like log is not available in the global scope, for example you've imported it only inside a module of your application, so it's only defined in that scope. Does that sound plausible?

If you want to access log globally, you'll either need to import it globally somehow, or more likely you want to expose it globally from your application code, e.g. by putting window.log = log inside your application code.

nboxall1 commented 3 years ago

Yes, window.log = log in my root project file did it for me. Thanks so much for the instant response!

pimterry commented 3 years ago

No problem, glad to hear that worked for you!