Python logging.DEBUG level doesn't logging

Question:

I have a problem with python’s logging lib. With the code below I create a “logger”:

logger = logging.getLogger()
def logger_init(level):
    try:
        syslog = SysLogHandler(address=LOG_DESTINATION)
    except Exception, ex:
        return
    formatter = logging.Formatter('%(module)s[%(process)d]: %(message)s')
    syslog.setFormatter(formatter)
    syslog.setLevel(level)
    logger.addHandler(syslog)

And I call it like:

logger.debug(SOME_STR_TO_BE_LOGGED)

OR like:

logger.error(SOME_STR_TO_BE_LOGGED)

And I initialize the logger with:

log_level = logging.ERROR
if options.DEBUG_LOG: ####  This comes from options parser and it is True.
    log_level = logging.DEBUG
logger_init(log_level)

The problem is that the error, and warn is working very well, but neither info nor debug methods prints anything to syslog.

I’m using syslog-ng and I designed my filter, that is it will accept every level from debug to emerg.

What is the problem here? Any ideas?

Asked By: 0xmtn

||

Answers:

You also have to set the level of the logger, not only the handler.

Add this to your logger_init:

logger.setLevel(level)
Answered By: Daniel Hepper
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.