1

Is there anything in this code that would explain why my info messages aren't going into the log. Properly formatted warnings and above are going into both log files.

Initializing logger:

logger = logging.getLogger() f = logging.Formatter('%(asctime)s\n%(levelname)s: %(funcName)s %(message)s') out = logging.handlers.RotatingFileHandler(filename=self.f_stdout, maxBytes=1048576, backupCount=99) err = logging.handlers.RotatingFileHandler(filename=self.f_stderr, maxBytes=1048576, backupCount=99) out.setLevel(logging.INFO) err.setLevel(logging.WARNING) err.setFormatter(f) logger.addHandler(out) logger.addHandler(err) 

Usage:

logging.info('this doesnt get logged') logging.warning('this gets logged to stdout and stderr with respective formatting') 

1 Answer 1

4

You never actually set the log level of the root logger object itself (the logger variable in your code). Both handlers and loggers have log levels; lines only reach the output if they're above both thresholds.

Since you don't set the root log level, it uses its default (warning). Try adding a call to logger.setLevel(logging.INFO) to change that.

Sign up to request clarification or add additional context in comments.

1 Comment

This has been bugging me since 1995 - THANK YOU!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.