logdown.js icon indicating copy to clipboard operation
logdown.js copied to clipboard

Specify log level with Node environment variable

Open bennycode opened this issue 5 years ago • 8 comments

With NODE_DEBUG it's possible to specify logger names which should be active. Is there also a setting to specify the log level?

For example, I would like to see only logs from "foo" which have log level "warning" or "error" but no "debug", "info" and/or "log".

I would like to set something like:

NODE_DEBUG=foo NODE_DEBUG_LEVEL=error,warn node example/node.js

bennycode avatar Feb 09 '20 13:02 bennycode

This is a really important feature.

rNoz avatar Feb 24 '20 11:02 rNoz

That's indeed a good feature to have. Are those values enough?:

  • log (should console info as well)
  • warn -error

caiogondim avatar Mar 02 '20 19:03 caiogondim

I suggest to use the 5 default levels from Logdown which are:

  1. debug
  2. log
  3. info
  4. warn
  5. error

When setting the log level to "error", then you will only get error reports. If you set the level to "warn", then you will get warnings and errors. When setting it to "info", you will get infos, warnings and errors. So the idea is that you get the level specified and all above.

bennycode avatar Mar 02 '20 20:03 bennycode

I thought log and info meant the same thing in modern implementations since it behaves the same in Chrome. But it's on the spec so I say we go with what @bennyn is proposing.

caiogondim avatar Mar 02 '20 22:03 caiogondim

Also, we need an env var for the browser as we do for window.localStorage.debug.

caiogondim avatar Mar 02 '20 22:03 caiogondim

How about window.localStorage.debugLevel?

bennycode avatar Mar 02 '20 23:03 bennycode

To clarify, if I set NODE_DEBUG_LEVEL as debug I would get:

  • debug
  • log
  • info
  • warn
  • error

If I set NODE_DEBUG_LEVEL as warn I would get

  • warn
  • error

Is that how you see it?

caiogondim avatar Mar 04 '20 16:03 caiogondim

Yes, exactly! 👍

bennycode avatar Mar 04 '20 16:03 bennycode