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. >> 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. > 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. >>> 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
