为什么 Heroku 使用服务器时间而不是 Rails 时区进行日志记录? [英] Why does Heroku log using the server time rather than the Rails time zone?

查看:18
本文介绍了为什么 Heroku 使用服务器时间而不是 Rails 时区进行日志记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:好的,我没有制定一个好的问题来回答.我仍然在为 heroku 在 -07:00 UTC 而我在 +02:00 UTC 而苦苦挣扎.

UPDATE: Ok, I didn't formulate a good Q to be answered. I still struggle with heroku being on -07:00 UTC and I at +02:00 UTC.

问:如何将日志写入正确的 Time.zone 中?9 小时的差异,heroku(美国西部) - 挪威,令人分心工作.我在我的 production.log 中得到了这个(使用 heroku 日志):

Q: How do I get the log written in the correct Time.zone ? The 9 hours difference, heroku (us west) - norway, is distracting to work with. I get this in my production.log (using heroku logs):

将 ProductionController#create 处理为 xml(用于 2010-04-28 23:00:12 的 81.26.51.35)[POST]

Processing ProductionController#create to xml (for 81.26.51.35 at 2010-04-28 23:00:12) [POST]

我如何让它写2010-04-29 08:00:12 +02:00 GMT?

请注意,我在 heroku 上运行,无法自己设置服务器时间,就像在您的 amazon EC2 服务器上一样.下面是我之前的问题,我会保留它,因为它包含一些有关时区的有趣信息.

Note that I'm running at heroku and cannot set the server time myself, as one could do at your amazon EC2 servers. Below is my previous question, I'll leave it be as it holds some interesting information about time and zones.

当我在 environment.rb

config.time_zone = 'Copenhagen'

我已经把它放在一个视图中

I've put this in a view

<p> Time.zone <%= Time.zone %> </p>
<p> Time.now <%= Time.now %> </p>
<p> Time.now.utc <%= Time.now.utc %> </p>
<p> Time.zone.now <%= Time.zone.now %>  </p>
<p> Time.zone.today <%= Time.zone.today %> </p>

在我的 heroku 应用程序上呈现这个结果

rendering this result on my app at heroku

时区 (GMT+01:00) 哥本哈根

Time.zone (GMT+01:00) Copenhagen

Time.now Mon Apr 26 08:28:21 -07002010

Time.now Mon Apr 26 08:28:21 -0700 2010

Time.now.utc 星期一 4 月 26 日 15:28:21 UTC2010

Time.now.utc Mon Apr 26 15:28:21 UTC 2010

Time.zone.now 2010-04-26 17:28:21+0200

Time.zone.now 2010-04-26 17:28:21 +0200

Time.zone.today 2010-04-26

Time.zone.today 2010-04-26

Time.zone.now 产生正确的结果.我是否必须在任何地方从 Time.now 切换到 Time.zone.now?看起来很麻烦.我真的不在乎服务器的本地时间是什么,由于广泛使用 Time.now,这给我带来了很多麻烦.我是否误解了这里的任何基本知识?

Time.zone.now yields the correct result. Do I have to switch from Time.now to Time.zone.now, everywhere? Seems cumbersome. I truly don't care what the local time of the server is, it's giving me loads of trouble due to extensive use of Time.now. Am I misunderstanding anything fundamental here?

推荐答案

在对我自己的 Heroku 时区问题进行一些进一步调查后,我发现了一篇帖子,表明您实际上可以在应用程序级别,使用以下命令:

After some further investigation into my own Heroku timezone problems, I found a post which indicates that you actually can specify the timezone at an application level, using the following command:

heroku config:add TZ=Europe/Oslo

我相信这可能是您所有烦恼的答案.由 http://www.reality.hk/articles/2010/01/提供07/1319/(截至 2012 年 8 月 23 日已断开链接.存档副本.)

I believe this may be the answer to all your troubles. Courtesy of http://www.reality.hk/articles/2010/01/07/1319/ ( Broken link as of 2012.08.23. Archived copy.)

这篇关于为什么 Heroku 使用服务器时间而不是 Rails 时区进行日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆