From 556a0220734097aa4e9fbfd93c8f263684232b3b Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Mon, 7 Aug 2017 13:38:56 -0500 Subject: Configure logging module to always use UTC time. Currently the python logging module will default to a local time which may contain an TZ offset in the values it produces, but the logged time format does not contain the offset. Switching to UTC time for logging produces consistent values in the cloud-init.log file and avoids issues when the timezone is changed during boot. LP: #1713158 --- cloudinit/log.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'cloudinit/log.py') diff --git a/cloudinit/log.py b/cloudinit/log.py index 3861709e..1d75c9ff 100644 --- a/cloudinit/log.py +++ b/cloudinit/log.py @@ -19,6 +19,8 @@ import sys import six from six import StringIO +import time + # Logging levels for easy access CRITICAL = logging.CRITICAL FATAL = logging.FATAL @@ -32,6 +34,9 @@ NOTSET = logging.NOTSET # Default basic format DEF_CON_FORMAT = '%(asctime)s - %(filename)s[%(levelname)s]: %(message)s' +# Always format logging timestamps as UTC time +logging.Formatter.converter = time.gmtime + def setupBasicLogging(level=DEBUG): root = logging.getLogger() -- cgit v1.2.3