在Ruby on Rails中设置日志记录级别 [英] Set logging levels in Ruby on Rails
问题描述
我正在使用以下代码在Ruby on Rails应用程序中配置日志记录:
I'm using following code to configure logging in my Ruby on Rails application:
environment.rb:
environment.rb:
Rails.logger = Logger.new(STDOUT)
class Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
end
end
我正尝试将日志记录级别设置为现在使用来警告
I'm trying to set the logging level to warn now using
config.log_level = :warn
在我的production.rb中,但似乎不起作用.我在这里想念什么吗?
in my production.rb, but it doens't seem to work. Am I missing something here?
如果我在我的environment.rb中放入Rails.logger.level = 4,它似乎确实可以工作.但是我想在环境初始化程序中配置这些东西.
If I put Rails.logger.level = 4 in my environment.rb, it does seem to work. But I would like to configure things in my environment initializers.
推荐答案
根据官方文档,您应该使用:
config.log_level = :warn # In any environment initializer, or
Rails.logger.level = 0 # at any time
如果这些都不适合您,请尝试:
If neither of those work for you, try:
config.log_level = Logger::WARN
如果这不起作用,请尝试:
And if that doesn't work, try:
config.logger.level = Logger::WARN
注意::最终方法似乎是将两种官方策略混为一谈,但在某些情况下可行
Note: The final method appears to be conflating the two official strategies, but works in some situations
这篇关于在Ruby on Rails中设置日志记录级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!