summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2016-01-05 16:47:42 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-01-05 21:14:44 -0800
commit9fce7075d992a5fc03476169600823b207ae5ff2 (patch)
tree98ccbca4dfb20c15fdfba0b105c2cb6a5ebce638
parent5f18982f6784f1f323ae93ed88ea7b82bdb14b2b (diff)
downloadchrome-ec-9fce7075d992a5fc03476169600823b207ae5ff2.tar.gz
util: ec3po: Add served PTY to logging.
Some devices have multiple ECs (main EC and PD MCU) and therefore there are multiple consoles and interpreters running concurrently. This commit prepends each log message with the served PTY to identify which of the console or interpreter instances the log message comes from. BUG=None BRANCH=None TEST=Ran ec3po in servo for samus. Noticed each debug print with the different PTYs for the main EC as well as the PD MCU. TEST=util/ec3po/run_tests.sh Change-Id: Icc69d2257172f4fedc217572ad0b6d15dac40387 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/320597 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Wai-Hong Tam <waihong@chromium.org>
-rwxr-xr-xutil/ec3po/console.py3
-rw-r--r--util/ec3po/interpreter.py11
2 files changed, 12 insertions, 2 deletions
diff --git a/util/ec3po/console.py b/util/ec3po/console.py
index 86a4a9be8c..d7dec24877 100755
--- a/util/ec3po/console.py
+++ b/util/ec3po/console.py
@@ -120,7 +120,8 @@ class Console(object):
read-only side of the debug pipe. This must be a unidirectional pipe
attached to the intepreter. EC debug messages use this pipe.
"""
- self.logger = logging.getLogger('EC3PO.Console')
+ logger = logging.getLogger('EC3PO.Console')
+ self.logger = interpreter.LoggerAdapter(logger, {'pty': user_pty})
self.master_pty = master_pty
self.user_pty = user_pty
self.cmd_pipe = cmd_pipe
diff --git a/util/ec3po/interpreter.py b/util/ec3po/interpreter.py
index 2d40729aaf..d8ebc6f536 100644
--- a/util/ec3po/interpreter.py
+++ b/util/ec3po/interpreter.py
@@ -29,6 +29,14 @@ EC_SYN = '\xec' # Byte indicating EC interrogation.
EC_ACK = '\xc0' # Byte representing correct EC response to interrogation.
+class LoggerAdapter(logging.LoggerAdapter):
+ """Class which provides a small adapter for the logger."""
+
+ def process(self, msg, kwargs):
+ """Prepends the served PTY to the beginning of the log message."""
+ return '%s - %s' % (self.extra['pty'], msg), kwargs
+
+
class Interpreter(object):
"""Class which provides the interpretation layer between the EC and user.
@@ -78,7 +86,8 @@ class Interpreter(object):
log_level: An optional integer representing the numeric value of the log
level. By default, the log level will be logging.INFO (20).
"""
- self.logger = logging.getLogger('EC3PO.Interpreter')
+ logger = logging.getLogger('EC3PO.Interpreter')
+ self.logger = LoggerAdapter(logger, {'pty': ec_uart_pty})
self.ec_uart_pty = open(ec_uart_pty, 'a+')
self.cmd_pipe = cmd_pipe
self.dbg_pipe = dbg_pipe