Start log tracing to log business events. Storage in both database and logging-backend.
This commit is contained in:
25
common/utils/business_event_context.py
Normal file
25
common/utils/business_event_context.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from werkzeug.local import LocalProxy, LocalStack
|
||||
|
||||
_business_event_stack = LocalStack()
|
||||
|
||||
|
||||
def _get_current_event():
|
||||
top = _business_event_stack.top
|
||||
if top is None:
|
||||
raise RuntimeError("No business event context found. Are you sure you're in a business event?")
|
||||
return top
|
||||
|
||||
|
||||
current_event = LocalProxy(_get_current_event)
|
||||
|
||||
|
||||
class BusinessEventContext:
|
||||
def __init__(self, event):
|
||||
self.event = event
|
||||
|
||||
def __enter__(self):
|
||||
_business_event_stack.push(self.event)
|
||||
return self.event
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
_business_event_stack.pop()
|
||||
Reference in New Issue
Block a user