rack-timeout: turn off info/active logging

一笑奈何 提交于 2019-12-07 13:56:20

问题


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


回答1:


(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



回答2:


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



回答3:


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" }


来源:https://stackoverflow.com/questions/33030781/rack-timeout-turn-off-info-active-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!