summaryrefslogtreecommitdiff
path: root/util/ec3po
diff options
context:
space:
mode:
authorTim Wawrzynczak <twawrzynczak@chromium.org>2019-03-11 13:13:48 -0600
committerchrome-bot <chrome-bot@chromium.org>2019-03-20 23:55:15 -0700
commit51c89799e029ded73601181eabe285ccdbc86888 (patch)
tree75f326d77f0f68262aed485bc12e5ce34b09ac3a /util/ec3po
parentf0ad0ca5af8dc1e9306a8e010d372107a66613c8 (diff)
downloadchrome-ec-51c89799e029ded73601181eabe285ccdbc86888.tar.gz
console: add time stamp to EC logs
Prefix all EC log lines with the host's current time, in YYYY-MM-DD HH:MM:SS format BUG=b:111675966 BRANCH=none TEST=manual, verify functionality while connected to console via servod & miniterm Change-Id: I3ac26301e781a1992628d43c6d6add1eed0ac91f Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1515815 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'util/ec3po')
-rwxr-xr-xutil/ec3po/console.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/util/ec3po/console.py b/util/ec3po/console.py
index b706c5f166..8206df437a 100755
--- a/util/ec3po/console.py
+++ b/util/ec3po/console.py
@@ -13,9 +13,10 @@ session-persistent command history.
from __future__ import print_function
import argparse
+import binascii
import copy
import ctypes
-import binascii
+from datetime import datetime
# pylint: disable=cros-logging-import
import logging
import os
@@ -60,6 +61,8 @@ ENHANCED_EC_INTERROGATION_TIMEOUT = 1.0 # Maximum number of seconds to wait for
INTERROGATION_MODES = ['never', 'always', 'auto'] # List of modes which control
# when interrogations are
# performed with the EC.
+# Format for printing host timestamp
+HOST_STRFTIME="%Y-%m-%d %H:%M:%S "
class EscState(object):
@@ -858,6 +861,9 @@ def StartLoop(console, command_active, shutdown_pipe=None):
# an iteration.
continue_looping = True
+ # Used for determining when to print host timestamps
+ tm_req = True
+
while continue_looping:
# Check to see if pts is connected to anything
events = ep.poll(0)
@@ -950,7 +956,27 @@ def StartLoop(console, command_active, shutdown_pipe=None):
('u' if master_connected else '') +
('i' if command_active.value else ''), data.strip())
if master_connected:
- os.write(console.master_pty, data)
+
+ # A timestamp is required at the beginning of this line
+ if tm_req is True:
+ now = datetime.now()
+ tm = now.strftime(HOST_STRFTIME)
+ os.write(console.master_pty, tm)
+ tm_req = False
+
+ # Insert timestamps into the middle where appropriate
+ # except if the last character is a newline
+ end = len(data) - 1
+ nls_found = data.count('\n', 0, end)
+ now = datetime.now()
+ tm = now.strftime('\n' + HOST_STRFTIME)
+ data_tm = data.replace('\n', tm, nls_found)
+
+ # timestamp required on next input
+ if data[end] == '\n':
+ tm_req = True
+
+ os.write(console.master_pty, data_tm)
if command_active.value:
os.write(console.interface_pty, data)