Skip to content

Instantly share code, notes, and snippets.

@papaben
Created November 6, 2018 16:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save papaben/31d154a32a1b99eb3b03b6efe2a34de7 to your computer and use it in GitHub Desktop.
Save papaben/31d154a32a1b99eb3b03b6efe2a34de7 to your computer and use it in GitHub Desktop.
Figure out who disabled your logger
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)
@wd
Copy link

wd commented Jul 18, 2019

Thanks for the code, it really helps.

@AlexandrDragunkin
Copy link

python 3.7 does not work

logging.Logger._disabled = logging.Logger.disabled

builtins.AttributeError: type object 'Logger' has no attribute 'disabled'

@AlexandrDragunkin
Copy link

Everything is working. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment