Redirect logger output for a specific controller in Rails 3

后端 未结 3 1028
日久生厌
日久生厌 2021-02-09 14:40

We want to have a collection of controllers where we route logger output from all actions and downstream methods to a separate log file. This is a Rails 3 project. In Rails 2 we

3条回答
  •  后悔当初
    2021-02-09 15:04

    To add on top of @messanjah's answer, you can overwrite these loggers: Rails::logger, ActionView::Base.logger, ActionController::Base.logger, ActiveRecord::Base.logger.

    By suppressing these loggers you get rid of most messages. But as @mudasobwa pointed Started ... messages are written before controller.

    If you don't want to use a middleware you can always use the hammer and monkeypatch Rails::Rack::Logger to use your logger aplication wide. Or you can check for path and reject certain messages there.

提交回复
热议问题