MCPcopy Index your code
hub / github.com/python/cpython / handleError

Method handleError

Lib/logging/__init__.py:1063–1108  ·  view source on GitHub ↗

Handle errors which occur during an emit() call. This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging syst

(self, record)

Source from the content-addressed store, hash-verified

1061 del _handlers[self._name]
1062
1063 def handleError(self, record):
1064 """
1065 Handle errors which occur during an emit() call.
1066
1067 This method should be called from handlers when an exception is
1068 encountered during an emit() call. If raiseExceptions is false,
1069 exceptions get silently ignored. This is what is mostly wanted
1070 for a logging system - most users will not care about errors in
1071 the logging system, they are more interested in application errors.
1072 You could, however, replace this with a custom handler if you wish.
1073 The record which was being processed is passed in to this method.
1074 """
1075 if raiseExceptions and sys.stderr: # see issue 13807
1076 exc = sys.exception()
1077 try:
1078 sys.stderr.write('--- Logging error ---\n')
1079 traceback.print_exception(exc, limit=None, file=sys.stderr)
1080 sys.stderr.write('Call stack:\n')
1081 # Walk the stack frame up until we're out of logging,
1082 # so as to print the calling context.
1083 frame = exc.__traceback__.tb_frame
1084 while (frame and os.path.dirname(frame.f_code.co_filename) ==
1085 __path__[0]):
1086 frame = frame.f_back
1087 if frame:
1088 traceback.print_stack(frame, file=sys.stderr)
1089 else:
1090 # couldn't find the right stack frame, for some reason
1091 sys.stderr.write('Logged from file %s, line %s\n' % (
1092 record.filename, record.lineno))
1093 # Issue 18671: output logging message and arguments
1094 try:
1095 sys.stderr.write('Message: %r\n'
1096 'Arguments: %s\n' % (record.msg,
1097 record.args))
1098 except RecursionError: # See issue 36272
1099 raise
1100 except Exception:
1101 sys.stderr.write('Unable to print the message and arguments'
1102 ' - possible formatting error.\nUse the'
1103 ' traceback above to help find the error.\n'
1104 )
1105 except OSError: #pragma: no cover
1106 pass # see issue 5971
1107 finally:
1108 del exc
1109
1110 def __repr__(self):
1111 level = getLevelName(self.level)

Callers 1

emitMethod · 0.45

Calls 4

print_stackMethod · 0.80
exceptionMethod · 0.45
writeMethod · 0.45
dirnameMethod · 0.45

Tested by

no test coverage detected