Python logging module emits wrong timezone information

前端 未结 2 1441
孤城傲影
孤城傲影 2021-01-12 01:47

I\'m running into an issue with Python 2.7 logging module. My system is Ubuntu 14.04 64bit, and I live in Italy (currently UTC+1, no daylight saving); the system is properly

2条回答
  •  既然无缘
    2021-01-12 02:25

    EDIT:

    You can set the time formatter by:

    logging.Formatter.converter = time.localtime
    

    to yield local time.

    Or:

    logging.Formatter.converter = time.gmtime
    

    to get UTC.

    As for local time + time zone, first of all, logging.Formatter uses time, which as you can see here does not really support TZ properly (look at the footnote).

    The cleanest alternative would be to write your own formatter that uses datetime, which apparently has quite the stupid way of using TZ. Basically to make your object "aware", I would go with pytz.

提交回复
热议问题