mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Ensure exception tracebacks are logged in the server log
This commit is contained in:
parent
b7e4dcc400
commit
bf0909669d
@ -7,12 +7,10 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import unittest, shutil, time, httplib, traceback
|
import unittest, time, httplib
|
||||||
from functools import partial
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from calibre.utils.logging import ThreadSafeLog
|
|
||||||
|
|
||||||
rmtree = partial(shutil.rmtree, ignore_errors=True)
|
from calibre.srv.utils import ServerLog
|
||||||
|
|
||||||
class BaseTest(unittest.TestCase):
|
class BaseTest(unittest.TestCase):
|
||||||
|
|
||||||
@ -21,13 +19,6 @@ class BaseTest(unittest.TestCase):
|
|||||||
|
|
||||||
ae = unittest.TestCase.assertEqual
|
ae = unittest.TestCase.assertEqual
|
||||||
|
|
||||||
class TestLog(ThreadSafeLog):
|
|
||||||
|
|
||||||
def exception(self, *args, **kwargs):
|
|
||||||
limit = kwargs.pop('limit', None)
|
|
||||||
self.prints(self.ERROR, *args, **kwargs)
|
|
||||||
self.prints(self.WARN, traceback.format_exc(limit))
|
|
||||||
|
|
||||||
class TestServer(Thread):
|
class TestServer(Thread):
|
||||||
|
|
||||||
daemon = True
|
daemon = True
|
||||||
@ -43,7 +34,7 @@ class TestServer(Thread):
|
|||||||
self.loop = ServerLoop(
|
self.loop = ServerLoop(
|
||||||
create_http_handler(handler),
|
create_http_handler(handler),
|
||||||
opts=Options(**kwargs),
|
opts=Options(**kwargs),
|
||||||
log=TestLog(level=ThreadSafeLog.WARN),
|
log=ServerLog(level=ServerLog.WARN),
|
||||||
)
|
)
|
||||||
self.log = self.loop.log
|
self.log = self.loop.log
|
||||||
|
|
||||||
|
@ -178,6 +178,11 @@ def eintr_retry_call(func, *args, **kwargs):
|
|||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
# Logging {{{
|
||||||
|
|
||||||
|
class ServerLog(ThreadSafeLog):
|
||||||
|
exception_traceback_level = ThreadSafeLog.WARN
|
||||||
|
|
||||||
class RotatingStream(object):
|
class RotatingStream(object):
|
||||||
|
|
||||||
def __init__(self, filename, max_size=None, history=5):
|
def __init__(self, filename, max_size=None, history=5):
|
||||||
@ -215,11 +220,12 @@ class RotatingStream(object):
|
|||||||
atomic_rename(self.filename, '%s.%d' % (self.filename, 1))
|
atomic_rename(self.filename, '%s.%d' % (self.filename, 1))
|
||||||
self.set_output()
|
self.set_output()
|
||||||
|
|
||||||
class RotatingLog(ThreadSafeLog):
|
class RotatingLog(ServerLog):
|
||||||
|
|
||||||
def __init__(self, filename, max_size=None, history=5):
|
def __init__(self, filename, max_size=None, history=5):
|
||||||
ThreadSafeLog.__init__(self)
|
ServerLog.__init__(self)
|
||||||
self.outputs = [RotatingStream(filename, max_size, history)]
|
self.outputs = [RotatingStream(filename, max_size, history)]
|
||||||
|
# }}}
|
||||||
|
|
||||||
class HandleInterrupt(object): # {{{
|
class HandleInterrupt(object): # {{{
|
||||||
|
|
||||||
|
@ -166,6 +166,7 @@ class DevNull(Log):
|
|||||||
self.outputs = []
|
self.outputs = []
|
||||||
|
|
||||||
class ThreadSafeLog(Log):
|
class ThreadSafeLog(Log):
|
||||||
|
exception_traceback_level = Log.DEBUG
|
||||||
|
|
||||||
def __init__(self, level=Log.INFO):
|
def __init__(self, level=Log.INFO):
|
||||||
Log.__init__(self, level=level)
|
Log.__init__(self, level=level)
|
||||||
@ -179,7 +180,7 @@ class ThreadSafeLog(Log):
|
|||||||
limit = kwargs.pop('limit', None)
|
limit = kwargs.pop('limit', None)
|
||||||
with self._lock:
|
with self._lock:
|
||||||
Log.prints(self, ERROR, *args, **kwargs)
|
Log.prints(self, ERROR, *args, **kwargs)
|
||||||
Log.prints(self, DEBUG, traceback.format_exc(limit))
|
Log.prints(self, self.exception_traceback_level, traceback.format_exc(limit))
|
||||||
|
|
||||||
class ThreadSafeWrapper(Log):
|
class ThreadSafeWrapper(Log):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user