classification
Title: With logging.config.fileConfig can't create logger without handler
Type: behavior Stage:
Components: Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: sean, vinay.sajip
Priority: normal Keywords:

Created on 2009-07-10 13:28 by sean, last changed 2009-07-13 11:12 by vinay.sajip. This issue is now closed.

Messages (3)
msg90392 - (view) Author: Sean (sean) Date: 2009-07-10 13:28
Using "logging" module I can do the following:

    f = logging.Formatter("%(levelname)s: %(name)s: %(message)s")
    h = logging.StreamHandler()
    h.setLevel(logging.NOTSET)
    h.setFormatter(f)
    l = logging.getLogger()
    l.addHandler(h)

    l2 = logging.getLogger('x.y.z')
    l2.setLevel(logging.INFO)
    print len(l2.handlers)

    l2.critical('critical')
    l2.error('error')
    l2.warning('warning')
    l2.info('info')
    l2.debug('debug')

Note, the l2(x.y.z) logger does not have a handler (it just propagates
to the l(root) logger's handler) but the l2 logger does have a different
level set.

When I try to do this with logging.config.fileConfig it fails saying I
have not specified a handler for the x.y.z logger.  But I don't want to
specify a handler, I just want to set the level and have it propagate up
the hierarchy.

Am I doing something wrong?

Sean.

P.S. Here is the config file:

[loggers]
keys=root,xyz

[handlers]
keys=consoleStderr

[formatters]
keys=simpleFormatter

[logger_root]
level=NOTSET
handlers=consoleStderr

[logger_xyz]
level=DEBUG
qualname=x.y.z

[handler_consoleStderr]
class=StreamHandler
level=NOTSET
formatter=simpleFormatter
args=(sys.stderr,)

[formatter_simpleFormatter]
%(levelname)s: %(name)s: %(message)s
msg90393 - (view) Author: Sean (sean) Date: 2009-07-10 16:31
there is a missing "format=" on the last line of my config file. Doesn't
change the stated problem though.
msg90476 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2009-07-13 11:12
Just set up a handlers= line in the relevant sections. You don't have to
actually specify any handlers.
History
Date User Action Args
2009-07-13 11:12:33vinay.sajipsetstatus: open -> closed

nosy: + vinay.sajip
messages: + msg90476

resolution: not a bug
2009-07-10 16:31:07seansetmessages: + msg90393
2009-07-10 13:28:44seancreate