from logging import getLogger from logging.config import fileConfig try: from StringIO import StringIO except ImportError: from io import StringIO # create the loggers before config. getLogger("foo") getLogger("foo.child") getLogger("bar") getLogger("bar.child") # The logger below existing causes bar.child to be disabled. # Comment the line below out for things to work as expected. getLogger("bar-etc") config_file = StringIO(""" [loggers] keys = root, foo, bar [handlers] keys = console [formatters] keys = [logger_root] level = DEBUG handlers = console [logger_foo] level = DEBUG handlers = qualname = foo [logger_bar] level = DEBUG handlers = qualname = bar [handler_console] class = StreamHandler args = (sys.stderr,) level = NOTSET """) fileConfig(config_file) # now write to the loggers - foo.child works, bar.child does not due # to "bar-etc" existing. getLogger("foo").warn("foo warning") getLogger("foo.child").warn("foo.child warning") getLogger("bar").warn("bar warning") getLogger("bar.child").warn("bar.child warning") getLogger("bar-etc").warn("bar-etc warning")