diff --git a/README.md b/README.md index 46cc911279ca9e2d5b9273aab4d644de832f8387..8221d0f4e6ba31f577277f2994a23cf192003507 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 60bd419913e86126205441308b398be163516c76..670e53e73668ccebf20294b26beb82a6c041caa0 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 48367ebb88479a19fb28506ba101d7c1584721d0..38e048ae43954b85350541ff7b01aef9d17fbe50 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: