Skip to content

Commit

Permalink
docs(logging): advise to use log_exceptions="always" (#3577)
Browse files Browse the repository at this point in the history
  • Loading branch information
jderrien authored Jun 17, 2024
1 parent 1db20fc commit 12193b4
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions docs/usage/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Application and request level loggers can be configured using the :class:`~lites
formatters={
"standard": {"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"}
},
log_exceptions="always",
)
app = Litestar(route_handlers=[my_router_handler], logging_config=logging_config)
Expand All @@ -32,12 +33,21 @@ Application and request level loggers can be configured using the :class:`~lites
is keyed as ``queue_listener`` in the logging configuration. The above example is using this handler,
which is optimal for async applications. Make sure to use it in your own loggers as in the above example.

.. attention::

Exceptions won't be logged by default, except in debug mode. Make sure to use ``log_exceptions="always"`` as in the
example above to log exceptions if you need it.


Using Python standard library
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Standard Library Logging (Manual Configuration)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`logging <https://docs.python.org/3/howto/logging.html>`_ is Python's builtin standard logging library and can be
configured through ``LoggingConfig``.

`logging <https://docs.python.org/3/howto/logging.html>`_ is Python's builtin standard logging library and can be integrated with `LoggingConfig` as the `root` logging. By using `logging_config()()` you can build a `logger` to be used around your project.
The ``LoggingConfig.configure()`` method returns a reference to ``logging.getLogger`` which can be used to access a
logger instance. Thus, the root logger can retrieved with ``logging_config.configure()()`` as shown in the example
below:

.. code-block:: python
Expand All @@ -47,10 +57,11 @@ Standard Library Logging (Manual Configuration)
from litestar.logging import LoggingConfig
logging_config = LoggingConfig(
root={"level": logging.getLevelName(logging.INFO), "handlers": ["console"]},
root={"level": "INFO", "handlers": ["queue_listener"]},
formatters={
"standard": {"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"}
},
log_exceptions="always",
)
logger = logging_config.configure()()
Expand All @@ -67,7 +78,7 @@ Standard Library Logging (Manual Configuration)
logging_config=logging_config,
)
The above example is the same as using logging without the litestar LoggingConfig.
The above example is the same as using logging without the litestar ``LoggingConfig``.

.. code-block:: python
Expand Down Expand Up @@ -112,8 +123,8 @@ the part of the user. That is, if ``picologging`` is present the previous exampl
Using StructLog
^^^^^^^^^^^^^^^

`StructLog <https://www.structlog.org/en/stable/>`_ is a powerful structured-logging library. Litestar ships with a dedicated
logging plugin and config for using it:
`StructLog <https://www.structlog.org/en/stable/>`_ is a powerful structured-logging library. Litestar ships with a
dedicated logging plugin and config for using it:

.. code-block:: python
Expand Down

0 comments on commit 12193b4

Please sign in to comment.