Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
bb228f35
Unverified
Commit
bb228f35
authored
3 years ago
by
Nick Barrett
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Include exception in json logging (#11028)
parent
0b4d5ce5
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/11028.feature
+1
-0
1 addition, 0 deletions
changelog.d/11028.feature
synapse/logging/_terse_json.py
+6
-0
6 additions, 0 deletions
synapse/logging/_terse_json.py
tests/logging/test_terse_json.py
+28
-0
28 additions, 0 deletions
tests/logging/test_terse_json.py
with
35 additions
and
0 deletions
changelog.d/11028.feature
0 → 100644
+
1
−
0
View file @
bb228f35
Include
exception
information
in
JSON
logging
output.
Contributed
by
@Fizzadar
at
Beeper.
This diff is collapsed.
Click to expand it.
synapse/logging/_terse_json.py
+
6
−
0
View file @
bb228f35
...
...
@@ -65,6 +65,12 @@ class JsonFormatter(logging.Formatter):
if
key
not
in
_IGNORED_LOG_RECORD_ATTRIBUTES
:
event
[
key
]
=
value
if
record
.
exc_info
:
exc_type
,
exc_value
,
_
=
record
.
exc_info
if
exc_type
:
event
[
"
exc_type
"
]
=
f
"
{
exc_type
.
__name__
}
"
event
[
"
exc_value
"
]
=
f
"
{
exc_value
}
"
return
_encoder
.
encode
(
event
)
...
...
This diff is collapsed.
Click to expand it.
tests/logging/test_terse_json.py
+
28
−
0
View file @
bb228f35
...
...
@@ -198,3 +198,31 @@ class TerseJsonTestCase(LoggerCleanupMixin, TestCase):
self
.
assertEqual
(
log
[
"
url
"
],
"
/_matrix/client/versions
"
)
self
.
assertEqual
(
log
[
"
protocol
"
],
"
1.1
"
)
self
.
assertEqual
(
log
[
"
user_agent
"
],
""
)
def
test_with_exception
(
self
):
"""
The logging exception type & value should be added to the JSON response.
"""
handler
=
logging
.
StreamHandler
(
self
.
output
)
handler
.
setFormatter
(
JsonFormatter
())
logger
=
self
.
get_logger
(
handler
)
try
:
raise
ValueError
(
"
That
'
s wrong, you wally!
"
)
except
ValueError
:
logger
.
exception
(
"
Hello there, %s!
"
,
"
wally
"
)
log
=
self
.
get_log_line
()
# The terse logger should give us these keys.
expected_log_keys
=
[
"
log
"
,
"
level
"
,
"
namespace
"
,
"
exc_type
"
,
"
exc_value
"
,
]
self
.
assertCountEqual
(
log
.
keys
(),
expected_log_keys
)
self
.
assertEqual
(
log
[
"
log
"
],
"
Hello there, wally!
"
)
self
.
assertEqual
(
log
[
"
exc_type
"
],
"
ValueError
"
)
self
.
assertEqual
(
log
[
"
exc_value
"
],
"
That
'
s wrong, you wally!
"
)
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