]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-127313: Use getLogger() without argument to get root logger in logging...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 3 Feb 2026 14:55:25 +0000 (15:55 +0100)
committerGitHub <noreply@github.com>
Tue, 3 Feb 2026 14:55:25 +0000 (14:55 +0000)
gh-127313: Use getLogger() without argument to get root logger in logging cookbook (GH-143683)

Use getLogger() to get root logger in logging cookbook
(cherry picked from commit 53fecbe6e116a4426058b7d0f6c451719c72cb5b)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
Doc/howto/logging-cookbook.rst

index c53be94a74009d203cad2e5c0968a2a69de37293..cb51f52375a19f838ef7e677b4c00b9105454b11 100644 (file)
@@ -229,7 +229,7 @@ messages should not. Here's how you can achieve this::
    # tell the handler to use this format
    console.setFormatter(formatter)
    # add the handler to the root logger
-   logging.getLogger('').addHandler(console)
+   logging.getLogger().addHandler(console)
 
    # Now, we can log to the root logger, or any other logger. First the root...
    logging.info('Jackdaws love my big sphinx of quartz.')
@@ -637,7 +637,7 @@ the receiving end. A simple way of doing this is attaching a
 
    import logging, logging.handlers
 
-   rootLogger = logging.getLogger('')
+   rootLogger = logging.getLogger()
    rootLogger.setLevel(logging.DEBUG)
    socketHandler = logging.handlers.SocketHandler('localhost',
                        logging.handlers.DEFAULT_TCP_LOGGING_PORT)