【发布时间】:2011-11-07 17:51:03
【问题描述】:
我们在 Tomcat 上部署了一个 JRuby on Rails 2 应用程序,使用默认的 Rails 记录器。在我们越过 DST 边界一段时间后,我们发现应用程序已死,日志中显示以下错误消息:
org.jruby.rack.RackInitializationException: Shifting failed. '/tc_instance/applogs/search.log.20111106' already exists.
原木通常在午夜轮换。前一天的日志的最终时间戳始终为 23:59,除了11 月 6 日的日志,其时间戳为 22:59。
-rw-rw-rw- 300683179 Nov 3 23:59 search.log.20111103
-rw-rw-rw- 226082012 Nov 4 23:59 search.log.20111104
-rw-rw-rw- 79789353 Nov 5 23:59 search.log.20111105
-rw-rw-rw- 109080879 Nov 6 22:59 search.log.20111106
所以发生的事情是日志试图在晚上 11 点而不是午夜滚动。然后,当它尝试创建新一天的日志时,它使用的是相同的日期。
看来我们的配置有问题,或者日志轮换计时逻辑有错误。
这里是environment.rb的相关部分:
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names.
config.time_zone = 'UTC'
if defined?($servlet_context)
include_class java.lang.System
app_logs_path = System.getProperty("appLogsPath")
if app_logs_path.nil?
Rails.logger.error("***System Property 'appLogsPath' was not set. Please contact the system administrator immediately!")
else
config.logger = Logger.new("#{app_logs_path}/search.log", "daily")
config.logger.formatter = Logger::Formatter.new
config.logger.datetime_format = "%Y-%m-%d %H:%M:%S"
config.logger.level = Logger::Severity::WARN
def config.format_message(severity, timestamp, progname, msg)
"[#{timestamp.to_formatted_s(:db)} #{severity}] #{msg}\n"
end
end
end
我假设 'UTC' 的 config.time_zone 设置是针对 ActiveRecord 的,但我想知道这是否是原因。
我的问题是:可能是什么问题?另外,日志轮换时序逻辑在哪里?是在 Rails、Jruby-Rack 还是底层的日志机制中?
【问题讨论】:
标签: logging jruby dst jrubyonrails jruby-rack