diff options
author | Tony Asleson <tasleson@redhat.com> | 2016-08-12 15:20:49 -0500 |
---|---|---|
committer | Tony Asleson <tasleson@redhat.com> | 2016-08-29 15:26:55 -0500 |
commit | a0a2c84a26a9542d32fa7db1f7dcae8ccb8beb88 (patch) | |
tree | 3d9f7d46d871d21546bf17da585114877d4801ae | |
parent | 7e37e7fde4e683572fa3d9a640821ba9bd4bb3d0 (diff) | |
download | lvm2-a0a2c84a26a9542d32fa7db1f7dcae8ccb8beb88.tar.gz |
lvmdbusd: Add date & ts if running in a terminal
When we are running in a terminal it's useful to have a date & ts on log
output like you get when output goes to the journal. Check if we are
running on a tty and if we are, add it in.
-rw-r--r-- | daemons/lvmdbusd/utils.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/daemons/lvmdbusd/utils.py b/daemons/lvmdbusd/utils.py index 3dcb373b0..9db78570b 100644 --- a/daemons/lvmdbusd/utils.py +++ b/daemons/lvmdbusd/utils.py @@ -13,6 +13,7 @@ import inspect import ctypes import os import string +import datetime import dbus import dbus.service @@ -243,7 +244,13 @@ def _common_log(msg, *attributes): cfg.stdout_lock.acquire() tid = ctypes.CDLL('libc.so.6').syscall(186) - msg = "%d:%d - %s" % (os.getpid(), tid, msg) + if STDOUT_TTY: + msg = "%s: %d:%d - %s" % \ + (datetime.datetime.now().strftime("%b %d %H:%M:%S.%f"), + os.getpid(), tid, msg) + + else: + msg = "%d:%d - %s" % (os.getpid(), tid, msg) if STDOUT_TTY and attributes: print(color(msg, *attributes)) |