logging with logging.config.fileConfig

H

Herman

I tried to use file to config my logger and I got a weird situation
that each message is outputted twice...
Here is my scenario:
python: 2.6

file abc_logging.conf:

[loggers]
keys=root,abc

[handlers]
keys=consoleHandler

[formatters]
keys=detailFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler

[logger_abc]
level=DEBUG
handlers=consoleHandler
qualname=abc

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

[formatter_detailFormatter]
format=%(asctime)-15s %(levelname)s: %(filename)s:%(lineno)s: %(message)s
datefmt=%Y-%m-%d %H:%M:%S


Then in my program, i config the file with this:

SCRIPT_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
logging.config.fileConfig(SCRIPT_DIR + os.path.sep + 'abc_logging.conf')
LOG = logging.getLogger('abc')


I tried to print out the logger handlers with this:
print("*"*10)
print("number of handlers: %s" % len(LOG.handlers))
print(LOG.handlers)
LOG.debug(sql)

But there is no suspicious behavior:

**********
number of handlers: 1
[<logging.StreamHandler instance at 0xf23518>]
2012-02-19 12:21:56 DEBUG: abc.py:88: SELECT ...
2012-02-19 12:21:56 DEBUG: abc.py:88: SELECT ...
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top