(beginner) logging config not working
__peter__ at web.de
Sat Apr 30 07:09:17 CEST 2011
Unknown Moss wrote:
> This is a beginner question. Thanks for the hand.
> I've been asked to maintain some poorly constructed python code.
> Logging is weak. Getting it to work with python logging
> programmatically was easy.
> However, I'd like to refactor all the logging code into configuration
> since I see the need for other handlers in the future (syslog and
> possibly email).
> For now I just want to get console and log file working, but I'm
> having problems with the log file. I'm trying some test code. Here's
> my test script (logging_example.py):
> import logging
> import logging.config
> def main():
> logging.debug("debug check")
The above is a shortcut for
root = logging.getLogger("")
i. e. you are logging to the root logger. According to your config file
messages sent to the root logger are only handled by the console handler:
You can either change that by adding the file handler to the list of
handlers for the root logger
in the config file or by directing your logging messages to "mylogger" with
mylogger = logging.getLogger("mylogger")
Note that loggers are organized in a tree; messages sent to mylogger will be
propagated upwords to the root logger by default.
More information about the Python-list