Skip to content
Snippets Groups Projects
Unverified Commit ee5b7175 authored by SKAJohanVenter's avatar SKAJohanVenter
Browse files

SAR-150 Updated docs with new format. Updated filename check

parent 403ed13c
No related branches found
No related tags found
No related merge requests found
......@@ -128,35 +128,39 @@ def command(self, parameter_json):
# ...
```
The context handler logs to the root logger by default. Logs can be sent to a custom logger by passing a logger object as a keyword argument. Use `configure_logging` method for ska formatted logs.
The context handler logs to the local logger by default. Logs can be sent to a custom logger by passing a logger object as a keyword argument. Use `configure_logging` method for ska formatted logs.
**Example ska formatted logs for successful transaction**
Log message formats:
- On Entry:
- Transaction [id]: Enter [name] with parameters [arguments]
- Transaction[id]: Enter[name] with parameters [arguments] marker[marker]
- On Exit:
- Transaction [id]: Exit [name]
- Transaction[id]: Exit[name] marker[marker]
- On exception:
- Transaction [id]: Exception [name]
- Transaction[id]: Exception[name] marker[marker]
-- Stacktrace --
The marker can be used to match entry/exception/exit log messages.
```txt
1|2020-09-22T11:43:22.760Z|INFO|Dummy-1|__enter__|transactions.py#124|tango-device:log/test/upstream|Transaction [txn-local-20200922-232544376]: Enter[CallWithContext] with parameters[{"ArgKey2": "ArgVal2"}]
1|2020-09-22T11:43:22.782Z|INFO|Dummy-1|__exit__|transactions.py#133|tango-device:log/test/upstream|Transaction[txn-local-20200922-232544376]: Exit[CallWithContext]
1|2020-10-01T12:49:31.119Z|INFO|Thread-210|thread_with_transaction_exception|test_transactions_threaded.py#23|transaction_id:txn-local-20201001-981667980|Transaction[txn-local-20201001-981667980]: Enter[Command] with parameters [{}] marker[52764]
1|2020-10-01T12:49:31.129Z|INFO|Thread-210|thread_with_transaction_exception|test_transactions_threaded.py#23|transaction_id:txn-local-20201001-981667980|Transaction[txn-local-20201001-981667980]: Exit[Command] marker[52764]
```
**Example ska formatted logs for failed transaction**
```txt
1|2020-09-22T11:45:07.122Z|ERROR|Dummy-1|__exit__|transactions.py#131|tango-device:log/test/upstream|Transaction[txn-local-20200922-362753747]: Exception[CallRaisesException]
1|2020-10-01T12:51:35.588Z|INFO|Thread-204|thread_with_transaction_exception|test_transactions_threaded.py#23|transaction_id:txn-local-20201001-354400050|Transaction[txn-local-20201001-354400050]: Enter[Transaction thread [7]] with parameters [{}] marker[21454]
1|2020-10-01T12:51:35.598Z|ERROR|Thread-204|thread_with_transaction_exception|test_transactions_threaded.py#23|transaction_id:txn-local-20201001-354400050|Transaction[txn-local-20201001-354400050]: Exception[Transaction thread [7]] marker[21454]
Traceback (most recent call last):
File "LogTestUpstream.py", line 47, in CallRaisesException
raise RuntimeError("An exception has occured")
RuntimeError: An exception has occured
1|2020-09-22T11:45:07.123Z|INFO|Dummy-1|__exit__|transactions.py#133|tango-device:log/test/upstream|Transaction[txn-local-20200922-362753747]: Exit[CallRaisesException]
File "python_file.py", line 27, in thread_with_transaction_exception
raise RuntimeError("An exception has occurred")
RuntimeError: An exception has occurred
1|2020-10-01T12:51:35.601Z|INFO|Thread-204|thread_with_transaction_exception|test_transactions_threaded.py#23|transaction_id:txn-local-20201001-354400050|Transaction[txn-local-20201001-354400050]: Exit[Transaction thread [7]] marker[21454]
```
Requirements
......
......@@ -49,7 +49,7 @@ class TransactionIDTagsFilter(logging.Filter):
# From Python 3.8 we should rather use `stacklevel`
frame = self.get_frame()
if frame:
if record.filename.startswith("transactions.py") and record.funcName in [
if record.pathname == __file__ and record.funcName in [
"__enter__",
"__exit__",
]:
......@@ -99,11 +99,11 @@ class Transaction:
Log message formats:
On Entry:
Transaction[id]: Enter [name] with parameters [arguments]
Transaction[id]: Enter[name] with parameters [arguments] marker[marker]
On Exit:
Transaction[id]: Exit [name]
Transaction[id]: Exit[name] marker[marker]
On exception:
Transaction[id]: Exception [name]
Transaction[id]: Exception[name] marker[marker]
Stacktrace
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment