move logging to method in ErrorHandler
This commit is contained in:
parent
75fca1b9c7
commit
de6c646ee8
|
@ -46,7 +46,7 @@ class ErrorHandler:
|
||||||
try:
|
try:
|
||||||
response = handler(request=request, exception=exception)
|
response = handler(request=request, exception=exception)
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error(format_exc())
|
self.log(format_exc())
|
||||||
if self.debug:
|
if self.debug:
|
||||||
response_message = (
|
response_message = (
|
||||||
'Exception raised in exception handler "{}" '
|
'Exception raised in exception handler "{}" '
|
||||||
|
@ -58,8 +58,15 @@ class ErrorHandler:
|
||||||
return text('An error occurred while handling an error', 500)
|
return text('An error occurred while handling an error', 500)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def log(self, message, level='error'):
|
||||||
|
"""
|
||||||
|
Override this method in an ErrorHandler subclass to prevent
|
||||||
|
logging exceptions.
|
||||||
|
"""
|
||||||
|
getattr(log, level)(message)
|
||||||
|
|
||||||
def default(self, request, exception):
|
def default(self, request, exception):
|
||||||
log.error(format_exc())
|
self.log(format_exc())
|
||||||
if issubclass(type(exception), SanicException):
|
if issubclass(type(exception), SanicException):
|
||||||
return text(
|
return text(
|
||||||
'Error: {}'.format(exception),
|
'Error: {}'.format(exception),
|
||||||
|
|
|
@ -346,7 +346,11 @@ def serve(host, port, request_handler, error_handler, before_start=None,
|
||||||
# Register signals for graceful termination
|
# Register signals for graceful termination
|
||||||
if register_sys_signals:
|
if register_sys_signals:
|
||||||
for _signal in (SIGINT, SIGTERM):
|
for _signal in (SIGINT, SIGTERM):
|
||||||
loop.add_signal_handler(_signal, loop.stop)
|
try:
|
||||||
|
loop.add_signal_handler(_signal, loop.stop)
|
||||||
|
except NotImplementedError:
|
||||||
|
log.warn(('Sanic tried to use loop.add_signal_handler')
|
||||||
|
('but it is not implemented on this platform.'))
|
||||||
|
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user