中关村村草 发表于 2011-02-15 10:56

按日期存储Rails日志

按日期存储Rails日志


Ruby代码1.RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log", "daily")   ) I/ b( h3 n4 ]+ G0 y5 g, O2 |
RAILS_DEFAULT_LOGGER = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log", "daily")# |) M' u3 N; \实际上Rails做了一些优化,通过ActiveSupport::BufferedLogger来提高产品环境下的性能。所以比较好的做法是在config/environment.rb加入如下代码:

Ruby代码config.logger = begin
path = config.paths.log.to_a.first
logger = ActiveSupport::BufferedLogger.new(path, "daily")
logger.level = ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase)
logger.auto_flushing = false if Rails.env.production?
logger
rescue StandardError => e
logger = ActiveSupport::BufferedLogger.new(STDERR)   
logger.level = ActiveSupport::BufferedLogger::WARN
logger.warn(   
"Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. "+
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."6 Z2 a)
)   
logger   
end

bugbugbug3 发表于 2011-02-15 11:12

Thanks :>

2gua 发表于 2011-02-15 12:26

好。

中关村村草 发表于 2011-02-15 13:25

好。
2gua 发表于 2011-02-15 12:26 http://bbs.chinaunix.net/images/common/back.gif


    哈哈,怎么一个接着一个啊!

2gua 发表于 2011-02-15 13:41

回复 4# 中关村村草


    他是他,我是我,他不是我的马甲。

中关村村草 发表于 2011-02-15 15:23

回复 5# 2gua


    哈哈,我是说都赞美,得瑟一下而已!

2gua 发表于 2011-02-15 16:13

回复 6# 中关村村草


    :emn23:
页: [1]
查看完整版本: 按日期存储Rails日志