Created
November 22, 2015 10:24
-
-
Save gothma/2459959b58b8af895574 to your computer and use it in GitHub Desktop.
Python logging: Trigger exit on critical error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import logging | |
import sys | |
class ShutdownHandler(logging.Handler): | |
def emit(self, record): | |
print(record.msg, file=sys.stderr) | |
logging.shutdown() | |
sys.exit(1) | |
logging.getLogger().addHandler(ShutdownHandler(level=50)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This worked out a bit better for me. Sending
level
as a param tologging.Handler
doesn't work for me but manually checking it in emit withlogging.StreamHandler
as the base class worked.