Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.d/+support-logging-to-json.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Document how to log with structured (JSON) logs and add an optional dependency
to accomplish this.
1 change: 1 addition & 0 deletions docs/production.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Running in production
.. toctree::

production/task-queue
production/logging
39 changes: 39 additions & 0 deletions docs/production/logging.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
=====================
Logging in production
=====================

Structured logging with JSON
============================

For log analysis it is frequently useful to have the logs in a structured
format.

By installing ``python-json-logger`` (for instance via ``pip install
python-json-logger`` or ``pip install ".[jsonlogging]"``) and setting up
a logging formatter like this:

::

"formatters": {
..
"json": {
"()": "pythonjsonlogger.json.JsonFormatter",
"format": "asctime,levelname,name,message",
"style": ",",
},
..
},
"handlers": {
"json": {
"class": "logging.StreamHandler",
"formatter": "json",
},
},

... the logs produced by argus will be in JSON format.

See `Python logging LogRecord attributes
<https://docs.python.org/3/library/logging.html#logrecord-attributes>`_ for
other default keywords useful to put in the "format"-line. "message" is
a human-chosen plaintext explicitly written in the code and should always be
included.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ dev = [
"tox>=4",
"build", # for debugging builds/installs
]
jsonlogging = ["python-json-logger"]

[tool.hatch.version]
source = "versioningit"
Expand Down
Loading