I am using the logging module in an application and it occurred to me that it would be neat if the logging module supported a method which would gracefully close file handles etc and then close the application.
For example:
logger = logging.getLogger('my_app')
logger.fatal("We're toast!")
the fatal method (or some such) would then:
- log the message as normal
- logging.shutdown()
- Call sys.exit(1)
Thoughts? Does something like this exist? Is this a bad idea?
Why do I want this? Well there are a few places in my code where I want the app to die and it seems a waste to keep repeating the code to do 2 and 3.
Perhaps not the cleanest solution, but this springs to mind:
And in the actual code just raise any exception
Although that will give you a different logger. If it's just about the shutdown part, just use try/finally: