Django+Gunicorn 错误的日志时间戳
Django+Gunicorn incorrect logs timestamp
在我的 Django 设置和我的机器上,我配置了 utc+3 时间,所以期望以 utc+3 获取所有日志,但结果是,它们实际上非常混乱:
[2017-08-08 10:29:22 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2017-08-08 10:29:22 +0000] [1] [DEBUG] Arbiter booted
[2017-08-08 10:29:22 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000
[2017-08-08 10:29:22 +0000] [1] [INFO] Using worker: sync
[2017-08-08 10:29:22 +0000] [7] [INFO] Booting worker with pid: 7
[2017-08-08 10:29:23 +0000] [1] [DEBUG] 1 worker
[2017-08-08 13:29:26 +0300] [7] [INFO] [dashboard.views:9] Displaying menu
设置:
TIME_ZONE = 'Europe/Moscow'
USE_TZ = True
也许你可以提供一些hints/information如何配置或调试它?
有一刻我以为这是 gunicorn 的问题,但它使用 Django 设置所以我不知道出了什么问题:/
Gunicorn 日志记录时间不依赖于 Django 时区,而是在本地机器上,所以要获得正确的时区,您应该配置本地机器以及如何配置取决于 OS 是什么 运行就可以了。
对于Debian/Ubuntu:
- sudo dpkg-reconfigure tzdata
- Follow the directions in the terminal.
- The timezone info is saved in /etc/timezone - which can be edited or used below
如果您使用的是 CentOS,您可以在 this article.
中查看
其他选项请在Google中勾选。
希望对您有所帮助。
因此,时间戳是正确的,但由于我公司的代理设置而有所不同。事实证明,处理不同时区的最佳方法是在所有地方使用 utc,除了向用户展示。
在我的 Django 设置和我的机器上,我配置了 utc+3 时间,所以期望以 utc+3 获取所有日志,但结果是,它们实际上非常混乱:
[2017-08-08 10:29:22 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2017-08-08 10:29:22 +0000] [1] [DEBUG] Arbiter booted
[2017-08-08 10:29:22 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000
[2017-08-08 10:29:22 +0000] [1] [INFO] Using worker: sync
[2017-08-08 10:29:22 +0000] [7] [INFO] Booting worker with pid: 7
[2017-08-08 10:29:23 +0000] [1] [DEBUG] 1 worker
[2017-08-08 13:29:26 +0300] [7] [INFO] [dashboard.views:9] Displaying menu
设置:
TIME_ZONE = 'Europe/Moscow'
USE_TZ = True
也许你可以提供一些hints/information如何配置或调试它?
有一刻我以为这是 gunicorn 的问题,但它使用 Django 设置所以我不知道出了什么问题:/
Gunicorn 日志记录时间不依赖于 Django 时区,而是在本地机器上,所以要获得正确的时区,您应该配置本地机器以及如何配置取决于 OS 是什么 运行就可以了。
对于Debian/Ubuntu:
- sudo dpkg-reconfigure tzdata
- Follow the directions in the terminal.
- The timezone info is saved in /etc/timezone - which can be edited or used below
如果您使用的是 CentOS,您可以在 this article.
中查看其他选项请在Google中勾选。
希望对您有所帮助。
因此,时间戳是正确的,但由于我公司的代理设置而有所不同。事实证明,处理不同时区的最佳方法是在所有地方使用 utc,除了向用户展示。