1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-22 09:24:21 +01:00

better log handler

This commit is contained in:
kakwa 2015-06-24 22:33:28 +02:00
parent 84c3d9604f
commit be23277363

View File

@ -35,13 +35,25 @@ SESSION_KEY = '_cp_username'
# of cherrypy # of cherrypy
def syslog_error(msg='', context='', def syslog_error(msg='', context='',
severity=logging.INFO, traceback=False): severity=logging.INFO, traceback=False):
if traceback:
msg += cherrypy._cperror.format_exc() if traceback and msg == '':
msg = 'python exception'
if context == '': if context == '':
cherrypy.log.error_log.log(severity, msg) cherrypy.log.error_log.log(severity, msg)
else: else:
cherrypy.log.error_log.log(severity, cherrypy.log.error_log.log(severity,
' '.join((context, msg))) ' '.join((context, msg)))
if traceback:
try:
exc = sys.exc_info()
if exc == (None, None, None):
cherrypy.log.error_log.log(severity, msg)
import traceback
# log each line of the exception
for l in traceback.format_exception(*exc):
cherrypy.log.error_log.log(severity, l)
finally:
del exc
class LdapCherry(object): class LdapCherry(object):
@ -53,7 +65,7 @@ class LdapCherry(object):
) )
else: else:
cherrypy.log.error( cherrypy.log.error(
msg = "unkwon exception '%(e)s'" % { 'e' : str(e) }, msg = "unkwon exception: '%(e)s'" % { 'e' : str(e) },
severity = logging.ERROR severity = logging.ERROR
) )
# log the traceback as 'debug' # log the traceback as 'debug'