summaryrefslogtreecommitdiff
path: root/cloudinit/log.py
diff options
context:
space:
mode:
authorRyan Harper <ryan.harper@canonical.com>2017-08-07 13:38:56 -0500
committerScott Moser <smoser@ubuntu.com>2017-08-25 15:01:19 -0700
commit556a0220734097aa4e9fbfd93c8f263684232b3b (patch)
tree1fa3ffeea38e884e022520c2ff68540716c98525 /cloudinit/log.py
parent20ca23cab0bdfdffa567f8fb4b49f3727bac6444 (diff)
downloadvyos-cloud-init-556a0220734097aa4e9fbfd93c8f263684232b3b.tar.gz
vyos-cloud-init-556a0220734097aa4e9fbfd93c8f263684232b3b.zip
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
Diffstat (limited to 'cloudinit/log.py')
-rw-r--r--cloudinit/log.py5
1 files changed, 5 insertions, 0 deletions
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()