Skip to content

Instantly share code, notes, and snippets.

@mgedmin
Created January 19, 2012 21:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mgedmin/1642893 to your computer and use it in GitHub Desktop.
Save mgedmin/1642893 to your computer and use it in GitHub Desktop.
Python logging insanity
[loggers]
keys = root, foo
[logger_root]
handlers = stdout
level = DEBUG
[logger_foo]
qualname = foo
handlers =
[handlers]
keys = stdout
[handler_stdout]
class = StreamHandler
args = (sys.stdout,)
formatter = mine
[formatters]
keys = mine
[formatter_mine]
format = [%(name)s] %(levelname)s: %(message)s
import logging
import logging.config
one = logging.getLogger('one')
foo = logging.getLogger('foo')
logging.config.fileConfig('logpain.ini')
two = logging.getLogger('two')
one.info('hello')
two.info('world')
foo.info('bar')
# What do you expect to be printed? Neither 'one' nor 'two' are explicitly mentioned in the .ini file
[two] INFO: world
[foo] INFO: bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment