]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-127313: Use getLogger() without argument to get root logger in logging cookbook...
authorAN Long <aisk@users.noreply.github.com>
Tue, 3 Feb 2026 14:49:12 +0000 (23:49 +0900)
committerGitHub <noreply@github.com>
Tue, 3 Feb 2026 14:49:12 +0000 (15:49 +0100)
Use getLogger() to get root logger in logging cookbook

Doc/howto/logging-cookbook.rst

index 52537a91df542c1996a0cb0f6a76ae50a088db18..9633bc75f2c914db6e526fc83f602ce091e58e80 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.')
@@ -650,7 +650,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)