***
Wartungsfenster jeden ersten Mittwoch vormittag im Monat
***
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Invenio Config TUW
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Center for Research Data Management
Invenio Config TUW
Commits
41e0c8be
Commit
41e0c8be
authored
2 years ago
by
Moser, Maximilian
Browse files
Options
Downloads
Patches
Plain Diff
Handle working outside of request context in logging formatter
parent
87d888e4
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!36
Logging formatter outside of request context
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
invenio_config_tuw/formatters.py
+13
-6
13 additions, 6 deletions
invenio_config_tuw/formatters.py
with
13 additions
and
6 deletions
invenio_config_tuw/formatters.py
+
13
−
6
View file @
41e0c8be
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment