Skip to content

Instantly share code, notes, and snippets.

@carljm
Created March 24, 2015 01:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carljm/6bd0b1b87590b1429ce7 to your computer and use it in GitHub Desktop.
Save carljm/6bd0b1b87590b1429ce7 to your computer and use it in GitHub Desktop.
playing with logging
from logging.config import dictConfig
import logging
initial = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'foo.bar': {
'handlers': ['console'],
},
},
}
dictConfig(initial)
foobar1 = logging.getLogger('foo.bar')
foobar1.warn('warn from foo.bar (1)')
foobarbaz1 = logging.getLogger('foo.bar.baz')
foobarbaz1.warn('warn from foo.bar.baz (1)')
new = {
'version': 1,
'disable_existing_loggers': True,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'foo': {
},
},
'root': {
'handlers': ['console'],
},
}
dictConfig(new)
foobar2 = logging.getLogger('foo.bar')
foobar2.warn('warn from foo.bar (2)')
foobarbaz2 = logging.getLogger('foo.bar.baz')
foobarbaz2.warn('warn from foo.bar.baz (2)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment