diff options
-rwxr-xr-x | util/ec3po/console.py | 3 | ||||
-rw-r--r-- | util/ec3po/interpreter.py | 11 |
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 |