Logging Transaction
This module provides the transaction logging mechanism.
- class AsyncTransaction(name, params={}, transaction_id='', transaction_id_key='transaction_id', logger=None)[source]
- class Transaction(name, params={}, transaction_id='', transaction_id_key='transaction_id', logger=None)[source]
- class TransactionBase(name, params={}, transaction_id='', transaction_id_key='transaction_id', logger=None)[source]
Transaction context handler.
Provides:
- Transaction ID::* Re-use existing transaction ID, if available* If no transaction ID, or empty or None, then generate a new ID* context handler returns the transaction ID used- Log messages on entry, exit, and exceptiondef command(self, parameter_json): parameters = json.reads(parameter_json) with transaction('My Command', parameters) as transaction_id: # ... parameters['transaction_id'] = transaction_id device.further_command(json.dumps(pars)) # ... def command(self, parameter_json): parameters = json.reads(parameter_json) with transaction('My Command', parameters, transaction_id="123") as transaction_id: # ... parameters['transaction_id'] = transaction_id device.further_command(json.dumps(pars)) # ... def command(self, parameter_json): parameters = json.reads(parameter_json) parameters["txn_id_key"] = 123 with transaction('My Command', parameters, transaction_id_key="txn_id_key") as transaction_id: # ... parameters['transaction_id'] = transaction_id device.further_command(json.dumps(pars)) # ...
Log message formats:On Entry:Transaction[id]: Enter[name] with parameters [arguments] marker[marker]On Exit:Transaction[id]: Exit[name] marker[marker]On exception:Transaction[id]: Exception[name] marker[marker]Stacktrace- __init__(name, params={}, transaction_id='', transaction_id_key='transaction_id', logger=None)[source]
Create the transaction context handler.
A new transaction ID is generated if none is passed in via transaction_id or in params.
If there is a transaction ID in params and transaction_id is also passed in then the passed in transaction_id will take precedence.
However, if both transaction IDs provided in params and transaction_id are deemed invalid (not a string or an empty string), then a new transaction ID will be generated.
By default the key transaction_id will be used to get a transaction ID out of params. If a different key is required then transaction_id_key can be specified.
- Parameters
name (str) – A description for the context. This is usually the Tango device command.
params (dict) – The parameters will be logged and will be used to retrieve the transaction ID if transaction_id is not passed in, defaults to {}
transaction_id (str) – The transaction ID to be used for the context, defaults to “”
transaction_id_key (str) – The key to use to get the transaction ID from params, defaults to “transaction_id”
logger (Optional[logging.Logger], optional) – The logger to use for logging, by default None. If no logger is specified a new one named ska.transaction will be used.
- Raises
TransactionParamsError – If the params passed is not valid.