Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Added information about the JSON-like logging format for the standard library #3990

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
39 changes: 39 additions & 0 deletions docs/usage/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ below:
logging_config=logging_config,
)

If you want to use ``LoggingConfig`` with another format string style, you need add a key "style"

.. code-block:: python

logging_config = LoggingConfig(
...
formatters={
"standard": {"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s", "style": "%"}
},
...
)

The above example is the same as using logging without the litestar ``LoggingConfig``.

.. code-block:: python
Expand Down Expand Up @@ -114,6 +126,33 @@ The above example is the same as using logging without the litestar ``LoggingCon
route_handlers=[my_router_handler],
)

Formatter like JSON string
--------------------------

* printf-style String Formatting

.. code-block:: python

format = ('{"asctime": "%(asctime)s", "name": "%(name)s", "level": "%(levelname)s", "message": "%(message)s"}')

ch.setFormatter(logging.Formatter(format))

* str.format() String Formatting

.. code-block:: python

# The double bracket are an escaping construction.
format = ('{{"asctime": "{asctime}", "name": "{name}", "level": "{levelname}", "message": "{message}" }}')

ch.setFormatter(logging.Formatter(format, style="{"))

* string.Template String Formatting

.. code-block:: python

format = ('{"asctime": "$asctime", "name": "$name", "level": "$levelname", "message": "$message"}')

ch.setFormatter(logging.Formatter(format, style="$"))

Using Picologging
^^^^^^^^^^^^^^^^^
Expand Down
Loading