0

I'm trying to use python's logging class, and encountering an issue where nothing gets written to the log file. According to the python documentation, the general rule is the class won't tell you about a problem while executing:

"The logging package is designed to swallow exceptions which occur while logging in production"

But I'm interested to understand any issues logging is encountering. The doc goes on to mention you can set a module level variable, raiseExceptions to see some more verbosity.

My question is, how do I set that and/or is there a more direct way to go about debugging this sort of issue?

For reference, here is my implementation of logging (python 2.7):

numeric_log_level = getattr(logging, args.loglevel.upper(), None)
if not isinstance(numeric_log_level, int):
     raise ValueError('Invalid log level: %s' % args.loglevel)
logging.basicConfig\
    (filename=args.logfile, level=numeric_log_level, format="%(asctime)s - [client] - %(levelname)s - %(message)s")

1 Answer 1

1

The documentation you linked to goes on to mention it's already enabled:

The default value of raiseExceptions is True.

Essentially exceptions for misconfigured logging will by default be printed the stderr. So if you want to see any of these problems, watch the output of your app if you are running it in a terminal.

If you are running it as a service or daemon, make sure you direct the stderr to a file. There are many different ways to do this depending on how you are daemonizing your script, but one common way is

python script.py 2> /path/to/log_exceptions
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Martin. I am running it in a terminal, but not seeing any exceptions, and I have a logging stmt at startup so I should see something right away if there is a problem. Instead I get nothing and no log file.
What happens when u simply use logging.info('test')?
After redeploying to another host it works. Still not sure what was causing it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy 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.