【问题标题】:How to use logging module in python with different timestamp?如何在具有不同时间戳的python中使用日志记录模块?
【发布时间】:2014-04-11 14:54:24
【问题描述】:

我的位置比服务器位置晚 3 小时,我想在不更改服务器设置的情况下使我的日志时间与我的本地时间相同?

【问题讨论】:

标签: python logging


【解决方案1】:

答案是

import logging
import time

logging.basicConfig(format='%(asctime)s %(message)s')
logging.warning('server time')

logging.Formatter.converter = lambda self, current: time.localtime(current-3600*3)

logging.warning('time at your zone')

time.localtime 是服务器时间。然后我给了偏差-3600*3(或者+是可能的)。

【讨论】:

  • 谢谢,这正是我需要的。
猜你喜欢
  • 1970-01-01
  • 2010-10-29
  • 1970-01-01
  • 1970-01-01
  • 2020-08-11
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 2011-09-13
相关资源
最近更新 更多