Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rack-timeout: turn off info/active logging

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

like image 258
Marklar Avatar asked Oct 09 '15 05:10

Marklar


4 Answers

(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
like image 114
Lucas Nelson Avatar answered Oct 28 '22 01:10

Lucas Nelson


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
like image 4
awolfson Avatar answered Oct 28 '22 00:10

awolfson


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)

like image 3
Hula_Zell Avatar answered Oct 27 '22 23:10

Hula_Zell


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" }
like image 1
DJSampat Avatar answered Oct 27 '22 23:10

DJSampat