From e310e2029102b5d63a679a2b64501c045aa86336 Mon Sep 17 00:00:00 2001 From: Delgan Date: Tue, 11 Feb 2025 15:32:26 +0100 Subject: [PATCH] Clarify documentation of "logger.exception()" --- loguru/_logger.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/loguru/_logger.py b/loguru/_logger.py index 867b004b4..911dd6043 100644 --- a/loguru/_logger.py +++ b/loguru/_logger.py @@ -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()` @@ -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)