[New-bugs-announce] [issue17749] root logging functions break logger configuration

Fabian report at bugs.python.org
Tue Apr 16 11:30:28 CEST 2013

New submission from Fabian:

If I get and configure a named logger in the main module and another module that is imported uses the root logging functions (e.g., logging.info("Hello World!")) somehow affects the configuration of the first (named) logger.

The file m1.py defines the logger "testlogger" and then imports the module m2.py. In m2.py the root logger is used through logging.info(...). This message apparantly doesn't appear anywhere.

After the import in m1.py the previously defined logger is used through logger.info(...). This message appears (formatted) in the logfile:

2013-04-16 11:23:56,231   INFO   Hello from __main__

and (unformatted) at stdout:

INFO:testlogger:Hello from __main__

I did not expect this behavior, therefore I reported this bug. In my expectation the call to logging.info() should not affect the behavior of the named and configured logger.

Main module (m1.py):

import logging

def setup_logging():
    # made this a function to avoid cluttering the global namespace
    logger = logging.getLogger("testlogger")
    formatter = logging.Formatter('%(asctime)s   %(levelname)s   %(message)s')
    handler = (logging.FileHandler("testlog.log"),
    handler = handler[0] # 0 : write to logfile, 1 : write to stdout
    return logger

logger = setup_logging()

import m2

logger.info("Hello from %s", __name__)

Other module (m2.py)

import logging
logging.info("Hello from %s", __name__)

I observed this behavior with Python v2.7.3

components: IO
messages: 187061
nosy: fmueller
priority: normal
severity: normal
status: open
title: root logging functions break logger configuration
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list