Skip to content

Return log.debug → console.debug mapping #126

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

Closed
kiyanovsky opened this issue Oct 20, 2018 · 6 comments
Closed

Return log.debug → console.debug mapping #126

kiyanovsky opened this issue Oct 20, 2018 · 6 comments

Comments

@kiyanovsky
Copy link

Hi,

In task #111, you decided to map log.debug to console.log. In the latest Chrome version,

  1. there is console.debug()
  2. they behave differently, namely:
  • console.log and console.info shows messages in "info" section
  • console.debug shows messages in "verbose" section

Now, when you map debug to log, both debug and info levels are shown in info. It'd be helpful to see them in different sections as they are supposed to be.

Best regards,
Andrey.

@pimterry
Copy link
Owner

@kiyanovsky I don't think this is correct. I'm using Chrome 70, which I think is the latest, and with 'Default levels' selected in the console, console.debug('test') prints nothing.

I agree the current behaviour isn't perfect but I don't have a better alternative. The current implementation ensures that the visibility of debug messages is configurable with loglevel, even if not they're not as filterable with Chrome's tools as they could be. Changing back to using console.debug directly again would mean that log.debug calls aren't printed, even if the level is enabled in loglevel, which caused a lot of user confusion in the past.

It is awkward that Chrome behaves this way, but given the tradeoffs I still think it's the right choice.

@kiyanovsky
Copy link
Author

Hi Tim,

I use Chrome 70 (screenshot). And console.debug gives you the debug (verbose) message: screenshot. Maybe you have debug messages turned off in the console, but it doesn't mean the console.debug doesn't work.

Also, console.debug is documented (although, it doesn't behave as the documentation says).

@kiyanovsky
Copy link
Author

Is there a workaround so I can tell log level to use console.debug for log.debug?

@pimterry
Copy link
Owner

pimterry commented Oct 25, 2018

Yes, it's existed and been logged for a very long time, that's not the problem. The problem is that the recent default level filters hide verbose logs, so many users get confused. Example:

screenshot from 2018-10-25 19-01-12

Note that 'Default levels' is selected as the log filter, as it is by default. You must've changed this, but most users aren't aware it exists, which causes problems.

If you really want to work around this for your case, you can write a plugin to do so. Docs are here: https://github.com/pimterry/loglevel#writing-plugins. I expect it'd be something like:

let originalFactory = log.methodFactory;
log.methodFactory = function (methodName, logLevel, loggerName) {
    if (methodName !== 'debug') {
		return originalFactory(methodName, logLevel, loggerName);
	} else {
		return console.debug;
	}
};
log.setLevel(log.getLevel()); // Be sure to call setLevel method in order to apply plugin

(EDIT: Updated with typo fix mentioned below)

This is a quick hack, and I haven't tested it, but it should be pretty close. Note that I've skipped the extra logic to handle console.debug not being available/needing to be bound/etc. If you're only worried about Chrome & modern browsers though you don't need that. If you want the full logic, you can follow it from https://github.com/pimterry/loglevel/blob/master/lib/loglevel.js#L92-L98, and copy across whatever bits you need.

@kiyanovsky
Copy link
Author

Thank you, Tim, the workaround works as expected! The only thing, you must be mistaken "method" for "methodName".

@pimterry
Copy link
Owner

Ah, yes, you're totally right 😄. Glad to hear that works for you!

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