-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
Configurable persistence #165
Comments
Hi @xmedeko. Could you tell me more about why you need to disable this? Right now, persistence is fully configurable at level configuration time - you can pass an option to Unfortunately, if it is a problem, it would be difficult to disable persistence at load time. By design loglevel is immediately initialized and available when imported, with zero options or construction required, to make it as easy as possible to quickly use. That means that |
I would like to disable it because it's useless for our Electron.js app. It's a very small slow down for every May be you think - hey, the slow down is negligible, why do you care? My reply is: why not to care? Why to have some code reading localStore and cookie which I do not need? IMO a good logging library should do just logging and everything else should be optional (or when default, then possible to opt-out.) And loglevel is almost like that except the persistence 😀 I understand it's not possible to change it for the current API. So I suggest:
|
It's not called every time you call Lines 247 to 252 in 342f103
I've done a little digging, and as far as I can tell in practice you'd have to instantiate many thousands of distinct logger instances before the local storage check has even 1ms total impact. If you're doing that much logging frequently enough that this has a measurable impact (e.g. creating 1000 loggers every second, each with distinct keys) then it's likely that you're generating huge amounts of logs, and that will be significantly more expensive than any localstorage lookups. That said, if you're committed to trying to avoid this regardless:
Honestly though, I don't think you should do any of this. LocalStorage is only expensive in comparison to bare object property lookups, loglevel is not optimized for performance to that degree at all, and unless you're working in some very specific high-performance environments the rest of your JS application is not either. There will be other much easier and more effective performance improvements in your code elsewhere! If you are doing a quantity of logging where this truly matters, and you're really really sure that this practically affects your performance, imo you're better off rolling your own microlibrary entirely. This is a tiny lib and it has lots of small UX & cross-browser compatibility details you could skip entirely for a custom case. There's probably many other micro-optimizations and simplifications here that would save >1ms in such an application, e.g. if you're calling getLogger billions of times then I suspect removing the argument validation checks in getLogger that happen on every call would make a bigger practical difference (but changes like that doesn't make sense for loglevel itself, since there's a UX tradeoff). |
I just repeat my previous comment:
Instead of require('loglevel').persistence = {
getLevel(loggerName) { ... },
setLevel(loggerName, levelName) { ... }
} Which would be more versatile. This is not a blocker for me, just IMO such things should be configurable. And, of course, I can always do copy&paste a remove that code. |
getPersistedLevel
is called for each logger. I do not need that. I think the persistence should be configurable same way asmethodFactory
for plugins - i.e. it should be possible to switch it off, use only cookies, etc.The text was updated successfully, but these errors were encountered: