In my Rails app production mode,I set the error log level to error
.
But I want to set some controllers an actions(or routes) to the level access
,so how can I realize this? If the log has a filter?
In my Rails app production mode,I set the error log level to error
.
But I want to set some controllers an actions(or routes) to the level access
,so how can I realize this? If the log has a filter?
You can use an around filter to adjust the logging level for an action, For example:
class MyBigFancyController < ApplicationController
around_action :adjust_logging_level_to_access, only: :show
def show
end
private
def adjust_logging_level_to_access
old_level = Rails.logger.level
Rails.logger.level = Logger::DEBUG
yield
Rails.logger.level = old_level
end
end
If you have to do this in many controllers, consider moving it to the ApplicationController.
Please note that adjusting the Rails logging level at run time is not thread safe. If you require thread safety, you will need to manually write to the log in the relevant locations.