Skip to content

Commit

Permalink
Clarify documentation of "logger.exception()"
Browse files Browse the repository at this point in the history
  • Loading branch information
Delgan committed Feb 11, 2025
1 parent 2dd470e commit e310e20
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion loguru/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
.. |patch| replace:: :meth:`~Logger.patch()`
.. |opt| replace:: :meth:`~Logger.opt()`
.. |log| replace:: :meth:`~Logger.log()`
.. |error| replace:: :meth:`~Logger.error()`
.. |level| replace:: :meth:`~Logger.level()`
.. |enable| replace:: :meth:`~Logger.enable()`
.. |disable| replace:: :meth:`~Logger.disable()`
Expand Down Expand Up @@ -2096,7 +2097,12 @@ def critical(__self, __message, *args, **kwargs): # noqa: N805
__self._log("CRITICAL", False, __self._options, __message, args, kwargs)

def exception(__self, __message, *args, **kwargs): # noqa: N805
r"""Log an ``'ERROR'```` message while also capturing the currently handled exception."""
r"""Log an ``'ERROR'`` message while also capturing the currently handled exception.
This method internally uses |sys.exc_info|, therefore it should only be called within
an ``except`` block. To log an exception that has already been caught, use the ``exception``
argument of |opt| along with a call to the |error| method (for example).
"""
options = (True,) + __self._options[1:]
__self._log("ERROR", False, options, __message, args, kwargs)

Expand Down

0 comments on commit e310e20

Please sign in to comment.