diff --git a/docs/usage/logging.rst b/docs/usage/logging.rst index 85269282c6..c0d2ad46c3 100644 --- a/docs/usage/logging.rst +++ b/docs/usage/logging.rst @@ -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) @@ -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 `_ is Python's builtin standard logging library and can be +configured through ``LoggingConfig``. -`logging `_ 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 @@ -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()() @@ -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 @@ -112,8 +123,8 @@ the part of the user. That is, if ``picologging`` is present the previous exampl Using StructLog ^^^^^^^^^^^^^^^ -`StructLog `_ is a powerful structured-logging library. Litestar ships with a dedicated -logging plugin and config for using it: +`StructLog `_ is a powerful structured-logging library. Litestar ships with a +dedicated logging plugin and config for using it: .. code-block:: python