-
-
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
Missing 'log' method to serve as a drop-in replacement for 'console' #64
Comments
I'd suggest using debug instead, for starters, since most browsers treat that as the standard default unmessed-around version. Anyway, I'm a bit averse to adding an actually adding a new case for I see your point about easy migration though. Would adding loglevel.log as an alias for loglevel.debug solve your problem? |
No, it does not. The browser console outputs the |
For me it is important that loglevel's api looks familiar to developers from non-JavaScript platforms. @sompylasar you can always decorate or wrap loglevel after loading it, or even create a plugin if you want. I use these two methods in a current project, so that including loglevel on a webpage is optional. function info() {
if (log) {
log.info.apply(null, arguments);
}
}
function error() {
if (log) {
log.error.apply(null, arguments);
}
} |
If non-JS developers are the target audience of this library, this should Decorating The browser console renders |
Which browser are you using that renders .debug and .log differently? In both Chrome and Firefox locally I see exactly the same thing. Chrome's own docs actually describe it as identical to console.log. Is there another browser that's not matching up with that? Non-JS developers aren't explicitly the target of this library, but you can't ignore context. Pretty much every other logging library everywhere, JS and otherwise, uses these levels. They're the standard log levels and I'm not going to deviate from that standard, because it's definitely going to be confusing to a substantial part of the userbase (anybody who has used any other logging libraries). I am quite happy to add an explicit alias, which it sounds like would solve the practical element of your problem (being able to quickly swap console for loglevel), if we can work out what level is suitable to alias to. I still don't think it's a good idea to actively use that though, except just to get started easily. This library isn't just a wrapper for console.log, it also provides the basic level of log level management that you need in any serious logging environment, and unfilterable logging (which I think is what you're suggesting) does not fit in that model (and is generally not a good idea in any meaningful codebase). I'm also curious why you don't want to persist the configured log level locally in your cookies/localStorage. Any particular reason for that? I'd originally added it because otherwise it's very fiddly to get log output for your app startup code without changing the live codebase. Is there a downside to this that you're hitting? |
I use the latest Google Chrome, the devtools console renders I needed a tiny library that copes with console inconsistencies and is I understand your thoughts on persistence: you want to visit your app in |
I'd like to +1 adding a "log" method. I just ran into this same issue while integrating loglevel. It's such a common method that it needs to be in the lib; I'd dare say that it's more often used the "info". |
I'll throw my two cents into the mix: Problems
|
Very good point @tauren 👍 One extra thing I did not find in documentation is if I can reset (persisted) log level after debugging session finished. There seem to be no The rest is very good (the right source of each message is a greatest pros of this library), ability to persist log level is also very cool. |
+1 to points made in @tauren reply I added a new level by |
piling on here, noting early comments in this thread it's important to point out that |
@shellscape the recommendation on MDN is to use Following the pattern it would become |
@victornpb I've implemented logging wrappers in the past, and we've always defaulted to the "plain" old log, equivalent to A further little tidbit, The argument for |
I'd rather not have a I do totally agree we need to find a solution now that |
Since browser logging methods do not fit the old good logging levels which every programmer (who programmed more than for the browser) used to, I would suggest to mimic those logging levels with the existing browser methods as close as possible. But there should exist all 6 levels.
+1 |
This seems like a good solution to me as well. Because
Why not just have Revised ProposalNow that
I've removed |
Optional persistence has actually already been added, since the initial discussion on this issue. See #72. As far as I'm aware loglevel will now never initially set anything in your storage, and
Sure, that's fine by me. I'd quite like to make sure it's clear in the docs that this isn't part of the recommended API, and it's just an bonus convenient alias, to keep the core API focused on the existing levels. I don't have any problem with it quietly existing though. I'll get around to doing all this and shipping a new release in the next week or two. If anybody wants it more urgently, or is feeling particularly keen, I'd welcome PRs in the meantime. I'd also welcome any more feedback: if anybody else has strong opinions on this, now's the time. |
I aprove the proposal apart from the verbose level. It's quite useful from having something above trace. |
Both the proposed changes have now been made, and released in 1.5.0:
|
I'd like to replace all
console.*
calls tologlevel.*
calls but I discovered that there is nolog
method which is widely used withconsole
. Theinfo
method does not fit well because the browser console highlights the info message with an icon making these messages somewhat more specific than default logging.Any chance adding
log
?The text was updated successfully, but these errors were encountered: