Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中使用具有不同时间戳的日志模块?_Python_Logging - Fatal编程技术网

如何在python中使用具有不同时间戳的日志模块?

如何在python中使用具有不同时间戳的日志模块?,python,logging,Python,Logging,我的位置与服务器位置相差3小时,我希望在不更改服务器设置的情况下使我的日志时间与本地时间相同?答案是 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) l

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

答案是

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
是服务器时间。然后我给了bias-3600*3(或+是可能的)。

可能重复感谢,这正是我需要的。