With the rack-timeout gem installed how is it possible to display ERROR only related logs? For example I would like to avoid having the below in my logs:
source=rack-timeout id=8a11a8ac3dadb59a4f347d8e365faddf timeout=20000ms service=0ms state=active
source=rack-timeout id=8a11a8ac3dadb59a4f347d8e365faddf timeout=20000ms service=49ms state=completed
source=rack-timeout id=ee947d4a291d02821ab108c4c127f555 timeout=20000ms state=ready
The following did not work:
Rack::Timeout.unregister_state_change_observer(:active)
The below may be on the right path but I'm having trouble testing:
Rack::Timeout::Logger.level = Logger::ERROR
(Note the class name was changed from Stage…
to State…
in v0.3.0)
In production I want to log at INFO
level so I get a log message per request, but I don't want this noise from rack-timeout.
You can alter the STATE_LOG_LEVEL
hash in the StateChangeLoggingObserver
and change the log level used for the different states. I use this in my initialiser to prevent the ready
and completed
logs from showing:
Rack::Timeout::StateChangeLoggingObserver::STATE_LOG_LEVEL[:ready] = :debug
Rack::Timeout::StateChangeLoggingObserver::STATE_LOG_LEVEL[:completed] = :debug
My solution to this problem was to give rack-timeout
its own logger.
Once you've done that, you can change its log level:
# config/initializers/timeout.rb
Rack::Timeout::Logger.logger = Logger.new("log/timeout.log")
Rack::Timeout::Logger.logger.level = Logger::ERROR
In config/initializers/rack_timeout.rb
I added:
Rack::Timeout::Logger.disable if Rails.env.development?
More detailed options are described here: https://github.com/sharpstone/rack-timeout/blob/master/doc/logging.md
(Thanks @Sandip Subedi for the suggestion)
Read here for more information
https://github.com/heroku/rack-timeout#rails-apps-manually or https://github.com/heroku/rack-timeout/blob/master/doc/settings.md
You could also try this code, though untested.
Rack::Timeout::StageChangeLoggingObserver.logger = logger = ::Logger.new(STDERR)
logger.level = ::Logger::DEBUG
logger.formatter = ->(severity, timestamp, progname, msg) {"[#{timestamp}] #{msg} at=#{severity.downcase}\n" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With