From ae663f14eb7a2cea916e4205d685914c072ab6e0 Mon Sep 17 00:00:00 2001 From: samueltwum1 <samueltwum1@gmail.com> Date: Wed, 16 Sep 2020 15:40:27 +0200 Subject: [PATCH] SAR-149 Pass the module-level logger object instead - Change file path in stack trace - Undo change to test_exception_logs_... in previous commit --- README.md | 2 +- src/ska/logging/transactions.py | 2 +- tests/test_transactions.py | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 46cc911..8221d0f 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ The context handler logs to the root logger by default. Logs can be sent to a cu 1|2020-09-15T10:54:17.266Z|ERROR|MainThread|__exit__|transactions.py#51||Transaction application encountered exception executing Scan, txn-T0001-20200914-00005 Traceback (most recent call last): - File "/home/sam/repos/lab/other/ska-logging/tests/test_transactions.py", line 93, in test_exception_logs_transaction_id_and_command + File "/ska-telescope/ska-logging/tests/test_transactions.py", line 93, in test_exception_logs_transaction_id_and_command raise RuntimeError("Something went wrong") RuntimeError: Something went wrong 1|2020-09-15T10:54:17.266Z|INFO|MainThread|__exit__|transactions.py#54||Exit transaction Scan, txn-T0001-20200914-00005 diff --git a/src/ska/logging/transactions.py b/src/ska/logging/transactions.py index 60bd419..670e53e 100644 --- a/src/ska/logging/transactions.py +++ b/src/ska/logging/transactions.py @@ -36,7 +36,7 @@ class Transaction: raise TransactionParamsError("params must be dict-like (Mapping)") self.logger = logger if not logger: - self.logger = logging + self.logger = logging.getLogger(__name__) self._name = name self._params = params self.transaction_id = self._get_existing_transaction_id() or self._generate_new_id() diff --git a/tests/test_transactions.py b/tests/test_transactions.py index 48367eb..38e048a 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -101,9 +101,11 @@ class TestTransactionLogging: raise RuntimeError("Something went wrong") record_logs = get_all_record_logs(recording_logger) - substrings = set(["RuntimeError", "name", transaction_id]) - result = [True for log_msg in record_logs if substrings.issubset(log_msg)] - assert all(result), f"Log messages not found in exception logs: {recording_logger}" + for log_msg in record_logs: + if "RuntimeError" in log_msg and transaction_id in log_msg and "name" in log_msg: + return + + assert 0, f"Log messages not found in exception logs: {record_logs}" class TestTransactionIdGenerator: -- GitLab