summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-02-12 16:24:45 (GMT)
committerGitHub <noreply@github.com>2024-02-12 16:24:45 (GMT)
commit91822018eeba12a6c9eabbc748363b2fd4291b30 (patch)
tree048ca3476c3f2bccf0ce450c2d23e3b14bcffe7a /Doc
parent814466101790d4381ca4800c3d3b0cc0aad50c62 (diff)
downloadcpython-91822018eeba12a6c9eabbc748363b2fd4291b30.zip
cpython-91822018eeba12a6c9eabbc748363b2fd4291b30.tar.gz
cpython-91822018eeba12a6c9eabbc748363b2fd4291b30.tar.bz2
gh-115233: Fix an example in the Logging Cookbook (GH-115325)
Also add more tests for LoggerAdapter. Also support stacklevel in LoggerAdapter._log().
Diffstat (limited to 'Doc')
-rw-r--r--Doc/howto/logging-cookbook.rst10
1 files changed, 4 insertions, 6 deletions
diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst
index 80147e3..f7d885e 100644
--- a/Doc/howto/logging-cookbook.rst
+++ b/Doc/howto/logging-cookbook.rst
@@ -1744,13 +1744,11 @@ to the above, as in the following example::
return self.fmt.format(*self.args)
class StyleAdapter(logging.LoggerAdapter):
- def __init__(self, logger, extra=None):
- super().__init__(logger, extra or {})
-
- def log(self, level, msg, /, *args, **kwargs):
+ def log(self, level, msg, /, *args, stacklevel=1, **kwargs):
if self.isEnabledFor(level):
msg, kwargs = self.process(msg, kwargs)
- self.logger._log(level, Message(msg, args), (), **kwargs)
+ self.logger.log(level, Message(msg, args), **kwargs,
+ stacklevel=stacklevel+1)
logger = StyleAdapter(logging.getLogger(__name__))
@@ -1762,7 +1760,7 @@ to the above, as in the following example::
main()
The above script should log the message ``Hello, world!`` when run with
-Python 3.2 or later.
+Python 3.8 or later.
.. currentmodule:: logging