Created
November 6, 2018 16:31
-
-
Save papaben/31d154a32a1b99eb3b03b6efe2a34de7 to your computer and use it in GitHub Desktop.
Figure out who disabled your logger
This file contains hidden or 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
def _get_trace(): | |
trace = u'' | |
depth = 2 # skip call to this function | |
while True: | |
try: | |
frame = sys._getframe(depth) | |
trace = u'%s:%s\n%s' % ( | |
frame.f_code.co_filename, frame.f_lineno, trace | |
) | |
depth += 1 | |
except ValueError: | |
break | |
return trace | |
def get_disabled(self): | |
return self._disabled | |
def set_disabled(self, disabled): | |
if disabled: | |
print('Logger %s --> %s' % (self.name, _get_trace())) | |
self._disabled = disabled | |
logging.Logger.disabled = property(get_disabled, set_disabled) |
python 3.7 does not work
logging.Logger._disabled = logging.Logger.disabled
builtins.AttributeError: type object 'Logger' has no attribute 'disabled'
Everything is working. Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the code, it really helps.