Skip to content
Snippets Groups Projects
Unverified Commit ae663f14 authored by samueltwum1's avatar samueltwum1
Browse files

SAR-149 Pass the module-level logger object instead

- Change file path in stack trace
- Undo change to test_exception_logs_... in previous commit
parent 643726a3
No related branches found
No related tags found
No related merge requests found
...@@ -146,7 +146,7 @@ The context handler logs to the root logger by default. Logs can be sent to a cu ...@@ -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 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): 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") raise RuntimeError("Something went wrong")
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 1|2020-09-15T10:54:17.266Z|INFO|MainThread|__exit__|transactions.py#54||Exit transaction Scan, txn-T0001-20200914-00005
......
...@@ -36,7 +36,7 @@ class Transaction: ...@@ -36,7 +36,7 @@ class Transaction:
raise TransactionParamsError("params must be dict-like (Mapping)") raise TransactionParamsError("params must be dict-like (Mapping)")
self.logger = logger self.logger = logger
if not logger: if not logger:
self.logger = logging self.logger = logging.getLogger(__name__)
self._name = name self._name = name
self._params = params self._params = params
self.transaction_id = self._get_existing_transaction_id() or self._generate_new_id() self.transaction_id = self._get_existing_transaction_id() or self._generate_new_id()
......
...@@ -101,9 +101,11 @@ class TestTransactionLogging: ...@@ -101,9 +101,11 @@ class TestTransactionLogging:
raise RuntimeError("Something went wrong") raise RuntimeError("Something went wrong")
record_logs = get_all_record_logs(recording_logger) record_logs = get_all_record_logs(recording_logger)
substrings = set(["RuntimeError", "name", transaction_id]) for log_msg in record_logs:
result = [True for log_msg in record_logs if substrings.issubset(log_msg)] if "RuntimeError" in log_msg and transaction_id in log_msg and "name" in log_msg:
assert all(result), f"Log messages not found in exception logs: {recording_logger}" return
assert 0, f"Log messages not found in exception logs: {record_logs}"
class TestTransactionIdGenerator: class TestTransactionIdGenerator:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment