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

D

Disc Magnet

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top