From 97a5952451596176625ea2364d8eaa766821f78f Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Tue, 5 Mar 2024 11:24:44 +0100 Subject: [PATCH] Fix #45: Document extra log fields --- docs/django.rst | 21 +++++++++++++++++++-- docs/fastapi.rst | 22 ++++++++++++++++++++-- docs/flask.rst | 22 ++++++++++++++++++++-- docs/sanic.rst | 22 ++++++++++++++++++++-- 4 files changed, 79 insertions(+), 8 deletions(-) diff --git a/docs/django.rst b/docs/django.rst index 6cad98b..d4b61d9 100644 --- a/docs/django.rst +++ b/docs/django.rst @@ -414,9 +414,26 @@ In order to include querystrings in the request summary log, set this flag in se DOCKERFLOW_SUMMARY_LOG_QUERYSTRING = True -A unique request ID is read from the `X-Request-ID` request header, and a UUID4 value is generated if unset. +MozLog App-Specific Fields +~~~~~~~~~~~~~~~~~~~~~~~~~~ -Leveraging the `RequestIdFilter` in logging configuration as shown above will add a ``rid`` attribute to all log messages. +The *MozLog* formatter will output ``Fields`` application-specific fields. It can be populated through the ``extra`` parameter: + +.. code-block:: python + + logger.info( + "Subsystem %s running at %s:%s", + name, host, port, + extra={"phase": "started", "host": host, "port": port} + ) + + +Requests Correlation ID +~~~~~~~~~~~~~~~~~~~~~~~ + +A unique request ID is read from the ``X-Request-ID`` request header, and a UUID4 value is generated if unset. + +Leveraging the ``RequestIdFilter`` in logging configuration as shown above will add a ``rid`` field into the ``Fields`` entry of all log messages. The header name to obtain the request ID can be customized in settings: diff --git a/docs/fastapi.rst b/docs/fastapi.rst index a701c50..fe4fe75 100644 --- a/docs/fastapi.rst +++ b/docs/fastapi.rst @@ -326,9 +326,27 @@ In order to include querystrings in the request summary log, set this flag in th app.state.DOCKERFLOW_SUMMARY_LOG_QUERYSTRING = True -A unique request ID is read from the `X-Request-ID` request header using the `RequestIdMiddleware` middleware (see :ref:`fastapi-setup`), and a UUID4 value is generated if unset. -Leveraging the `RequestIdFilter` in logging configuration as shown above will add a ``rid`` attribute to all log messages. +MozLog App-Specific Fields +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The *MozLog* formatter will output ``Fields`` application-specific fields. It can be populated through the ``extra`` parameter: + +.. code-block:: python + + logger.info( + "Subsystem %s running at %s:%s", + name, host, port, + extra={"phase": "started", "host": host, "port": port} + ) + + +Requests Correlation ID +~~~~~~~~~~~~~~~~~~~~~~~ + +A unique request ID is read from the ``X-Request-ID`` request header, and a UUID4 value is generated if unset. + +Leveraging the ``RequestIdFilter`` in logging configuration as shown above will add a ``rid`` field into the ``Fields`` entry of all log messages. The header name to obtain the request ID can be customized in settings: diff --git a/docs/flask.rst b/docs/flask.rst index 292bfa4..c77834e 100644 --- a/docs/flask.rst +++ b/docs/flask.rst @@ -466,9 +466,27 @@ In order to include querystrings in the request summary log, set this flag in :r DOCKERFLOW_SUMMARY_LOG_QUERYSTRING = True -A unique request ID is read from the `X-Request-ID` request header, and a UUID4 value is generated if unset. -Leveraging the `RequestIdFilter` in logging configuration as shown above will add a ``rid`` attribute to all log messages. +MozLog App-Specific Fields +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The *MozLog* formatter will output ``Fields`` application-specific fields. It can be populated through the ``extra`` parameter: + +.. code-block:: python + + logger.info( + "Subsystem %s running at %s:%s", + name, host, port, + extra={"phase": "started", "host": host, "port": port} + ) + + +Requests Correlation ID +~~~~~~~~~~~~~~~~~~~~~~~ + +A unique request ID is read from the ``X-Request-ID`` request header, and a UUID4 value is generated if unset. + +Leveraging the ``RequestIdFilter`` in logging configuration as shown above will add a ``rid`` field into the ``Fields`` entry of all log messages. The header name to obtain the request ID can be customized in settings: diff --git a/docs/sanic.rst b/docs/sanic.rst index 50e48d9..034272f 100644 --- a/docs/sanic.rst +++ b/docs/sanic.rst @@ -465,9 +465,27 @@ In order to include querystrings in the request summary log, set this flag in :r DOCKERFLOW_SUMMARY_LOG_QUERYSTRING = True -A unique request ID is read from the `X-Request-ID` request header, and a UUID4 value is generated if unset. -Leveraging the `RequestIdFilter` in logging configuration as shown above will add a ``rid`` attribute to all log messages. +MozLog App-Specific Fields +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The *MozLog* formatter will output ``Fields`` application-specific fields. It can be populated through the ``extra`` parameter: + +.. code-block:: python + + logger.info( + "Subsystem %s running at %s:%s", + name, host, port, + extra={"phase": "started", "host": host, "port": port} + ) + + +Requests Correlation ID +~~~~~~~~~~~~~~~~~~~~~~~ + +A unique request ID is read from the ``X-Request-ID`` request header, and a UUID4 value is generated if unset. + +Leveraging the ``RequestIdFilter`` in logging configuration as shown above will add a ``rid`` field into the ``Fields`` entry of all log messages. The header name to obtain the request ID can be customized in settings: