*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit 41e0c8be authored by Moser, Maximilian's avatar Moser, Maximilian
Browse files

Handle working outside of request context in logging formatter

parent 87d888e4
No related branches found
No related tags found
1 merge request!36Logging formatter outside of request context
......@@ -32,13 +32,20 @@ class CustomFormatter(Formatter):
"""Custom logging formatter that provides more details."""
def __init__(self, fmt=custom_format, **kwargs):
super(CustomFormatter, self).__init__(fmt=fmt, **kwargs)
super().__init__(fmt=fmt, **kwargs)
def format(self, record):
user_id = "Anonymous"
if current_user is not None and current_user.is_authenticated:
user_id = current_user.id
try:
user_id = "Anonymous"
if current_user and current_user.is_authenticated:
user_id = current_user.id
record.user_id = user_id
record.request_url = request.base_url
except RuntimeError:
# this happens when we're working outside a request context
record.user_id = None
record.request_url = None
record.user_id = user_id
record.request_url = request.base_url
return super(CustomFormatter, self).format(record)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment