Skip to content

Instantly share code, notes, and snippets.

@carljm

carljm/test.py

Created Mar 24, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.