In my Rails app production mode,I set the error log level to error
.
在我的Rails应用程序生产模式中,我将错误日志级别设置为错误。
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?
但我想为一些控制器设置一个操作(或路由)到级别访问,所以我怎么能意识到这一点?如果日志有过滤器?
1 个解决方案
#1
0
You can use an around filter to adjust the logging level for an action, For example:
您可以使用around过滤器来调整操作的日志记录级别,例如:
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.
如果必须在许多控制器中执行此操作,请考虑将其移动到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.
请注意,在运行时调整Rails日志记录级别不是线程安全的。如果您需要线程安全,则需要手动写入相关位置的日志。
#1
0
You can use an around filter to adjust the logging level for an action, For example:
您可以使用around过滤器来调整操作的日志记录级别,例如:
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.
如果必须在许多控制器中执行此操作,请考虑将其移动到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.
请注意,在运行时调整Rails日志记录级别不是线程安全的。如果您需要线程安全,则需要手动写入相关位置的日志。