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

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

问题描述

更新:好吧,我没有制定一个好的Q来回答。我仍然努力与heroku在-07:00 UTC和我在+02:00 UTC。



问:我如何获得写入日志正确的Time.zone?
9小时的差异,heroku(us west) - 挪威,与注意力分散。我在production.log中得到了这个(使用 heroku logs ):
$ b


处理ProductionController#create to xml(在 2010-04-28 23:00:12 中为81.26.51.35)[POST]


我如何获得 2010-04-29 08:00:12 +02:00 GMT



请注意,我在heroku上运行,无法自己设置服务器时间,因为您可以在您的amazon EC2服务器上执行此操作。下面是我以前的问题,我会留下它,因为它有关于时间和区域的一些有趣的信息。






为什么当我在 environment.rb 中设置另一个时区时,服务器本地时间会产生 Time.now p>

  config.time_zone ='Copenhagen'

我把它放在视图中

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

在我的应用上在 heroku

$ b上呈现此结果
$ b


Time.zone(GMT + 01:00)哥本哈根

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



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



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



时区。今天2010-04-26

Time.zone.now 会产生正确的结果。我是否必须从> Time.now 切换到 Time.zone.now ,到处?看起来很麻烦。我真的不在意服务器的本地时间,由于大量使用 Time.now ,给我带来了很多麻烦。我是否误解了这里的任何基础知识?

解决方案

经过对我自己的Heroku时区问题的进一步调查,我发现了一篇文章,您实际上可以使用以下命令在应用程序级别指定时区:

  heroku config:添加TZ =欧洲/奥斯陆

我相信这可能是您所有烦恼的答案。致谢 http://www.reality.hk/articles/2010/01/ 07/1319 / 修改:)截至2012年8月23日的链接。存档副本。)


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.

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):

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

How do I get it to write 2010-04-29 08:00:12 +02:00 GMT ?

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.


Why does Time.now yield the server local time when I have set the another time zone in my 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>

rendering this result on my app at heroku

Time.zone (GMT+01:00) Copenhagen

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

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

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

Time.zone.today 2010-04-26

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?

解决方案

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

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

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

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