← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~raharper/cloud-init:logging-gmtime into cloud-init:master


Ryan Harper has proposed merging ~raharper/cloud-init:logging-gmtime into cloud-init:master.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:

Configure logging module to always use UTC time (time.gmtime())

Currently the python logging module will default to a local time which may contain an TZ offset in the values it produces.  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.

Your team cloud-init commiters is requested to review the proposed merge of ~raharper/cloud-init:logging-gmtime into cloud-init:master.
diff --git a/cloudinit/log.py b/cloudinit/log.py
index 3861709..3a21ad2 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
 FATAL = logging.FATAL
@@ -32,6 +34,8 @@ 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()

Follow ups