34

I have a problem with python'slogging 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.ERRORif options.DEBUG_LOG: ####  This comes from options parser and it is True.    log_level = logging.DEBUGlogger_init(log_level)

The problem is that theerror, andwarn is working very well, but neitherinfo nordebug methods prints anything to syslog.

I'm using syslog-ng and I designed my filter, that is it will accept every level fromdebug toemerg.

What is the problem here? Any ideas?

askedDec 13, 2012 at 10:25
0xmtn's user avatar

1 Answer1

40

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

Add this to yourlogger_init:

logger.setLevel(level)
answeredDec 13, 2012 at 10:37
Daniel Hepper's user avatar
Sign up to request clarification or add additional context in comments.

1 Comment

spent some time scratching my head about this.. thanks a lot for helping catch it.

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.