On Mon, Mar 14, 2016 at 11:09 AM, sebb <[email protected]> wrote: > On 14 March 2016 at 14:22, Sam Ruby <[email protected]> wrote: >> On Mon, Mar 14, 2016 at 10:10 AM, sebb <[email protected]> wrote: >>> On 14 March 2016 at 12:55, sebb <[email protected]> wrote: >>>> It would be useful to be able to initialise the default log level but >>>> still allow CLI over-ride. >>>> >>>> I've found a hacky fix: >>>> >>>> Wunderbar.log_level = 'info' unless Wunderbar.log_level == 'debug' # >>>> don't override command-line level >>>> >>>> however that relies on knowing that debug (and only debug) is more >>>> verbose than info. >>> >>> I can improve that with: >>> >>> Wunderbar.log_level = 'info' unless Wunderbar.logger.info? >>> >>> however this still overrides a CLI arg of --warn etc. >>> >>> I tried another hack: >>> >>> ARGV.unshift '--info' >>> >>> at the start of the script, but that does not work properly because >>> Wunderbar does not process ARGV in order. >>> But even if it did, updating the args would be a hack. >>> >>> So I think there needs to be a way to override the default level. >> >> I just pushed out a change to wunderbar that adds that: >> >> https://github.com/rubys/wunderbar/commit/3e9472f811b616c190bc94d23606c4864ee104cc > > Thanks; that works provided the default is set before any logging takes place. > Also it can only be invoked once; subsequent invocations are silently ignored.
I thought that was sufficient to meet your needs? Or at least I did, until you mentioned stderr. >>> It would also be useful to be able to override the default output >>> stream; $stderr is not always suitable. >> >> If you need more interfaces, they can be added to wunderbar. > > I'm not sure that's an option for the output stream. > The default_log_level method instantiates the logger; it's then too > late to change the stream as there is no public API in Logger to do > so. > It would require creating a new Logger and copying across the existing > config. Messy. > > Also it's not as efficient as providing them in Wunderbar itself. > I don't think the enhancements are particularly esoteric. Agreed. Issues and/or patches welcome. Testing changes to wunderbar is simply a matter of cloning the repository and setting RUBYLIB or updating the Gemfile. >> Also, >> you can create your own logger: >> >> http://ruby-doc.org/stdlib-2.3.0/libdoc/logger/rdoc/Logger.html >> >> You can even make wunderbar use that logger: >> >> Wunderbar.logger = your_custom_logger > > Yes, but that needs code that basically repeats the existing > constructor; seems wasteful. At times I've thought that the right layering was that whimsy/asf would have its own logger, and would provide it to Wunderbar to deal with applications that use that library. I felt this way as it always felt strange that applications that don't otherwise use the wunderbar library make calls to it to set up logging. I never fully explored what it would take to do that. In any case, I'm quite open to updating wunderbar >>>> Also modifying the formatter message is a bit messy; it would be >>>> useful if this could be specified when creating the logger. >>>> >>>> I don't know how to do this in Ruby - if it's even possible? >> >> - Sam Ruby - Sam Ruby
