Rails 日志记录错误:“故障安全响应期间出错:转换失败。” ...有一个优雅的解决方案吗?

发布于 2024-09-12 07:12:57 字数 395 浏览 10 评论 0原文

我已经在environment.rb中将我的Rails 2.3.8记录器配置为每天轮换:

config.logger = Logger.new("#{RAILS_ROOT}/logs/#{RAILS_ENV}.log", 'daily')

并且每天早上我都会得到通常的信息:

Error during failsafe response: Shifting failed.

是否有一个体面/优雅/更好的解决方案?

我过去所做的只是设置一个 cron 作业来注意何时发生这种情况,并将 Passenger restart.txt 文件放入应用程序的 tmp/ 目录中。

谢谢。

I've configured my Rails 2.3.8 logger in the environment.rb to rotate daily:

config.logger = Logger.new("#{RAILS_ROOT}/logs/#{RAILS_ENV}.log", 'daily')

and every day in the morning I get the usual:

Error during failsafe response: Shifting failed.

Is there a decent/elegant/better solution to this?

What I've done in the past is just set up a cron job to notice when this happens and to drop a Passenger restart.txt file in the app's tmp/ directory.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾其所爱 2024-09-19 07:12:57

在 UNIX/Linux 上使用名为 logrotate 的程序来执行日志文件轮换是很常见的。 Slicehost 有几篇不错的文章介绍如何使用它。

对于 Phusion Passenger 部署,您可以使用如下例所示的配置。显然适当地调整目录和轮换频率。

/home/deploy/public_html/railsapp/shared/log/*.log {
  weekly
  missingok
  rotate 30
  compress
  delaycompress
  notifempty
  sharedscripts
  postrotate
    touch /home/deploy/public_html/railsapp/current/tmp/restart.txt
  endscript
}

It's pretty common on UNIX/Linux to use a program named logrotate to perform log file rotation. Slicehost have a couple of nice articles on how to use it.

For a Phusion Passenger deployment you can use a configuration like the example below. Obviously adjust the directories and rotation frequency as appropriate.

/home/deploy/public_html/railsapp/shared/log/*.log {
  weekly
  missingok
  rotate 30
  compress
  delaycompress
  notifempty
  sharedscripts
  postrotate
    touch /home/deploy/public_html/railsapp/current/tmp/restart.txt
  endscript
}
逆光飞翔i 2024-09-19 07:12:57

如果您同时收到许多请求,那么 Rails 就需要轮换日志了。如果一个流试图写入一个文件(logger.rb 代码中有一行写着:@dev.stat.size)并且当该文件不存在(因为它正在旋转)时,它会抛出一个致命异常,基本上,服务器停止响应请求(它不一定会关闭,但会轰炸请求。

If you have many requests coming in simultaneously, and it is time for the Rails to rotate logs. If a stream is trying to write to a file ( the logger.rb code has a line that says : @dev.stat.size) and when the file does not exist (because it is being rotated) then it throws a fatal exception, and basically the server stops responding to requests (it doesn’t necessarily shut down, but bombs out on requests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文