console icon indicating copy to clipboard operation
console copied to clipboard

Log level coupling to $VERBOSE and $DEBUG not always helpful

Open tadman opened this issue 4 years ago • 2 comments

Anyone who uses libraries that generate a lot of warnings will resort to using -W0 as a default in Ruby. This does silence the warnings, but it also has the unfortunate side-effect of pretty much silencing Console.logger as well since the default level now moves up a notch.

What's doubly frustrating is anyone with the -W0 default will not see output from Console examples, where this:

require 'console'

Console.logger.info("Hello World")

Does nothing at all. This can be reproduced with RUBYOPT=-W0 ruby example.rb

Overriding this within an application is not convenient. Right now what I've found you have to do is:

ENV['CONSOLE_LEVEL'] ||= 'info'

Where that's a really round-about way of setting a default. It would be more convenient if the default_log_level could be specified, as in Console::Logger.default_log_level = :debug or whatever setting is desired, where that will be applied to all loggers created after that point.

tadman avatar Jan 29 '21 10:01 tadman

I agree with you, but I'm also not sure what the solution is.

Basically... log data should always be some kind of non-essential "debug output".

I wanted to try and make it tie into existing Ruby constructs for controlling log level.

ioquatix avatar Apr 13 '21 07:04 ioquatix

There's nothing wrong with having defaults tied to Ruby's global verbosity level, but right now it's really awkward to try and separate those two to override it.

Most other logging tools, even Logger, support an arbitrary per-logger logging level override. Logger.new(level: :debug) for example.

tadman avatar May 01 '21 01:05 tadman