Don't print exceptions to stderr, log them instead, always force output
This commit is contained in:
parent
3a6319c1b9
commit
e9b7c6c439
@ -67,23 +67,26 @@ class ExceptionWrapper(Wrapper):
|
|||||||
try:
|
try:
|
||||||
self.workload()
|
self.workload()
|
||||||
except:
|
except:
|
||||||
sys.stderr.write("Exception in {thread} at {time}\n".format(
|
message = "\n> Exception in {thread} at {time}, module {name}".format(
|
||||||
thread=threading.current_thread().name,
|
thread=threading.current_thread().name,
|
||||||
time=time.strftime("%c")
|
time=time.strftime("%c"),
|
||||||
))
|
name=self.workload.__class__.__name__
|
||||||
traceback.print_exc(file=sys.stderr)
|
)
|
||||||
sys.stderr.flush()
|
if hasattr(self.workload, "logger"):
|
||||||
if hasattr(self.workload, "output"):
|
self.workload.logger.error(message, exc_info=True)
|
||||||
self.workload.output = {
|
self.workload.output = {
|
||||||
"full_text": "{}: {}".format(self.workload.__class__.__name__,
|
"full_text": "{}: {}".format(self.workload.__class__.__name__,
|
||||||
self.format_error(str(sys.exc_info()[1]))),
|
self.format_error(str(sys.exc_info()[1]))),
|
||||||
"color": "#FF0000",
|
"color": "#FF0000",
|
||||||
}
|
}
|
||||||
|
|
||||||
def format_error(self, exception_message):
|
def format_error(self, exception_message):
|
||||||
if hasattr(self.workload, 'max_error_len'):
|
if hasattr(self.workload, 'max_error_len'):
|
||||||
error_len = self.workload.max_error_len
|
error_len = self.workload.max_error_len
|
||||||
return exception_message[:error_len] + '...' if len(exception_message) > error_len else exception_message
|
if len(exception_message) > error_len:
|
||||||
|
return exception_message[:error_len] + '…'
|
||||||
|
else:
|
||||||
|
return exception_message
|
||||||
else:
|
else:
|
||||||
return exception_message
|
return exception_message
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user