logger warning doesn't appear even though propagate flag is True

Disc Magnet discmagnet at gmail.com
Mon Apr 18 22:03:49 CEST 2011


This program prints both the warnings:

#!/usr/bin/env python2.7

import logging
import logging.config

logging.config.fileConfig('log.conf')

log1 = logging.getLogger()
log2 = logging.getLogger('foo.bar')
log2.addHandler(logging.NullHandler())

log1.warn('warning 1')
log2.warn('warning 2')

However, this prints only the first warning:

#!/usr/bin/env python2.7

import logging
import logging.config

log2 = logging.getLogger('foo.bar')
logging.config.fileConfig('log.conf')

log1 = logging.getLogger()
log2.addHandler(logging.NullHandler())

log1.warn('warning 1')
log2.warn('warning 2')

My log.conf file is defined as:


[loggers]
keys=root

[handlers]
keys=consoleHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[formatter_simpleFormatter]
format=%(asctime)s %(name)s %(levelname)s - %(message)s
datefmt=%Y-%m-%d %H:%M:%S

Could you please explain why the second warning doesn't appear in the
second program?



More information about the Python-list mailing list