Reputation: 2167
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")
Upvotes: 0
Views: 230
Reputation: 59691
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
Upvotes: 1