diff options
author | Mary Ruthven <mruthven@google.com> | 2018-12-13 14:17:48 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-01-04 12:46:36 -0800 |
commit | a588c9e99e5f40d4f9af2ee24c8d27cd64ff2c1e (patch) | |
tree | 57f6641e3903be98dfb1f8572dd19bafe9ba8a5f | |
parent | 0d8358a854797867564bc4032dbe3296c3b040e4 (diff) | |
download | chrome-ec-a588c9e99e5f40d4f9af2ee24c8d27cd64ff2c1e.tar.gz |
ec3po: use source name in logger
Include the ec3po source name in the logger, so it is clear which
console is logging the messages.
BUG=none
BRANCH=none
TEST=none
Change-Id: I8d3bb330c3928b8f05078fd90b0238c4b027d90b
Signed-off-by: Mary Ruthven <mruthven@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1376776
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
-rwxr-xr-x | util/ec3po/console.py | 10 | ||||
-rwxr-xr-x | util/ec3po/console_unittest.py | 6 | ||||
-rw-r--r-- | util/ec3po/interpreter.py | 10 | ||||
-rwxr-xr-x | util/ec3po/interpreter_unittest.py | 6 |
4 files changed, 19 insertions, 13 deletions
diff --git a/util/ec3po/console.py b/util/ec3po/console.py index 4244061b5c..b706c5f166 100755 --- a/util/ec3po/console.py +++ b/util/ec3po/console.py @@ -132,7 +132,8 @@ class Console(object): interrogations are performed with the EC or not and how often. """ - def __init__(self, master_pty, user_pty, interface_pty, cmd_pipe, dbg_pipe): + def __init__(self, master_pty, user_pty, interface_pty, cmd_pipe, dbg_pipe, + name=None): """Initalises a Console object with the provided arguments. Args: @@ -148,10 +149,11 @@ class Console(object): represents the console's read-only side of the debug pipe. This must be a unidirectional pipe attached to the intepreter. EC debug messages use this pipe. + name: the console source name """ - # Copy the logger, so modifying one ec3po logger level will not modify the - # loglevel for every ec3po console. - logger = copy.copy(logging.getLogger('EC3PO.Console')) + # Create a unique logger based on the console name + console_prefix = ('%s - ' % name) if name else '' + logger = logging.getLogger('%sEC3PO.Console' % console_prefix) self.logger = interpreter.LoggerAdapter(logger, {'pty': user_pty}) self.master_pty = master_pty self.user_pty = user_pty diff --git a/util/ec3po/console_unittest.py b/util/ec3po/console_unittest.py index 22d468263b..72565ca510 100755 --- a/util/ec3po/console_unittest.py +++ b/util/ec3po/console_unittest.py @@ -241,7 +241,7 @@ class TestConsoleEditingMethods(unittest.TestCase): dummy_pipe_end_0, dummy_pipe_end_1 = threadproc_shim.Pipe() self.console = console.Console(self.tempfile.fileno(), self.tempfile, tempfile.TemporaryFile(), - dummy_pipe_end_0, dummy_pipe_end_1) + dummy_pipe_end_0, dummy_pipe_end_1, "EC") # Console editing methods are only valid for enhanced EC images, therefore # we have to assume that the "EC" we're talking to is enhanced. By default, @@ -1145,7 +1145,7 @@ class TestConsoleCompatibility(unittest.TestCase): dummy_pipe_end_0, dummy_pipe_end_1 = mock.MagicMock(), mock.MagicMock() self.console = console.Console(self.tempfile.fileno(), self.tempfile, tempfile.TemporaryFile(), - dummy_pipe_end_0, dummy_pipe_end_1) + dummy_pipe_end_0, dummy_pipe_end_1, "EC") @mock.patch('console.Console.CheckForEnhancedECImage') def test_ActAsPassThruInNonEnhancedMode(self, mock_check): @@ -1415,7 +1415,7 @@ class TestOOBMConsoleCommands(unittest.TestCase): dummy_pipe_end_0, dummy_pipe_end_1 = mock.MagicMock(), mock.MagicMock() self.console = console.Console(self.tempfile.fileno(), self.tempfile, tempfile.TemporaryFile(), - dummy_pipe_end_0, dummy_pipe_end_1) + dummy_pipe_end_0, dummy_pipe_end_1, "EC") self.console.oobm_queue = mock.MagicMock() @mock.patch('console.Console.CheckForEnhancedECImage') diff --git a/util/ec3po/interpreter.py b/util/ec3po/interpreter.py index 305dc81812..23eb6a6071 100644 --- a/util/ec3po/interpreter.py +++ b/util/ec3po/interpreter.py @@ -75,7 +75,8 @@ class Interpreter(object): connected: A boolean indicating if the interpreter is actually connected to the UART and listening. """ - def __init__(self, ec_uart_pty, cmd_pipe, dbg_pipe, log_level=logging.INFO): + def __init__(self, ec_uart_pty, cmd_pipe, dbg_pipe, log_level=logging.INFO, + name=None): """Intializes an Interpreter object with the provided args. Args: @@ -91,10 +92,11 @@ class Interpreter(object): should retry commands if it receives an error. log_level: An optional integer representing the numeric value of the log level. By default, the log level will be logging.INFO (20). + name: the console source name """ - # Copy the logger, so modifying one ec3po logger level will not modify the - # loglevel for every ec3po interpreter. - logger = copy.copy(logging.getLogger('EC3PO.Interpreter')) + # Create a unique logger based on the interpreter name + interpreter_prefix = ('%s - ' % name) if name else '' + logger = logging.getLogger('%sEC3PO.Interpreter' % interpreter_prefix) self.logger = LoggerAdapter(logger, {'pty': ec_uart_pty}) self.ec_uart_pty = open(ec_uart_pty, 'a+') self.ec_uart_pty_name = ec_uart_pty diff --git a/util/ec3po/interpreter_unittest.py b/util/ec3po/interpreter_unittest.py index 8b9578a242..57c9abf4ae 100755 --- a/util/ec3po/interpreter_unittest.py +++ b/util/ec3po/interpreter_unittest.py @@ -39,7 +39,8 @@ class TestEnhancedECBehaviour(unittest.TestCase): self.itpr = interpreter.Interpreter(self.tempfile.name, self.cmd_pipe_itpr, self.dbg_pipe_itpr, - log_level=logging.DEBUG) + log_level=logging.DEBUG, + name="EC") @mock.patch('interpreter.os') def test_HandlingCommandsThatProduceNoOutput(self, mock_os): @@ -274,7 +275,8 @@ class TestUARTDisconnection(unittest.TestCase): self.itpr = interpreter.Interpreter(self.tempfile.name, self.cmd_pipe_itpr, self.dbg_pipe_itpr, - log_level=logging.DEBUG) + log_level=logging.DEBUG, + name="EC") # First, check that interpreter is initialized to connected. self.assertTrue(self.itpr.connected, ('The interpreter should be' |