TwP / logging

A flexible logging library for use in Ruby programs based on the design of Java's log4j library.
https://rubygems.org/gems/logging
MIT License
529 stars 100 forks source link

Rails 5.0 silencer no longer compatible with logging gem #189

Open lzap opened 6 years ago

lzap commented 6 years ago

Hey, this was pain to solve so this is a pro-active issue, perhaps we can mention this in the readme or something.

Rails devs refactored logger silencing code in 5.0 (https://github.com/rails/rails/commit/2518bda97cbbcb33dc9a92e70d5b01c09e64d12d) in a way that the code responsible for storing temporary level is now part of logger instead of silencer. This renders logging gem incompatible if silence method is overridden in Rails app leading to loosing level on concurrent silencing access, which happens all the time for us (for example sprockets gem silences logs, we have silencers in our code as well). After some time or immediately after start, level is reset to error level which makes development impossible (no debug messages).

While I share your opinion that silencing is bad and I think it comes from fact that Ruby/Rails both don't have trace level (more than debug, useful as opt-in development level when haunting bugs), I think this is worth mentioning somewhere in docs. Of course, if an app keeps using your RailsCompat module (https://github.com/TwP/logging/issues/11) then there should be no problem, but pragmatic way of getting rid of too detailed logs is unfortunately to implement your own silence (until Rails adopts Logging gem :-)

For googlers, the obvious workaround is to store temporary levels in thread-local variables: https://github.com/theforeman/foreman/pull/5197