Return a sentence describing when this exception was already seen.
"""
exc_log=run_sql("SELECT last_notified,last_seen,total FROM hstEXCEPTION WHERE name=%s AND filename=%s AND line=%s",(name,filename,line))
ifexc_log:
last_notified,last_seen,total=exc_log[0]
return"This exception has already been seen %s times\n last time it was seen: %s\n last time it was notified: %s\n"%(total,last_seen.strftime("%Y-%m-%d %H:%M:%S"),last_notified.strftime("%Y-%m-%d %H:%M:%S"))
else:
return"It is the first time this exception has been seen.\n"
defregister_exception(stream='error',
req=None,
prefix='',
suffix='',
alert_admin=False,
subject=''):
"""
Log error exception to invenio.err and warning exception to invenio.log.
Errors will be logged together with client information (if req is
given).
Note: For sanity reasons, dynamic params such as PREFIX, SUFFIX and
local stack variables are checked for length, and only first 500
chars of their values are printed.
@param stream: 'error' or 'warning'
@param req: mod_python request
@param prefix: a message to be printed before the exception in
the log
@param suffix: a message to be printed before the exception in
the log
@param alert_admin: wethever to send the exception to the administrator via
email. Note this parameter is bypassed when
CFG_SITE_ADMIN_EMAIL_EXCEPTIONS is set to a value different than 1
@param subject: overrides the email subject
@return: 1 if successfully wrote to stream, 0 if not
"""
ifCFG_ERRORLIB_SENTRY_URI:
fromravenimportClient
client=Client(CFG_ERRORLIB_SENTRY_URI)
try:
ifreq:
# Inner class that will be used to preprocess the data
classSentryEncoder(json.JSONEncoder):
defdefault(self,obj):
try:
returnobj.__dict___
exceptAttributeError:
returnstr(obj)
frominvenio.webuserimportcollect_user_info
user_info=collect_user_info(req)
client.user_context({'id':user_info['uid'],
'is_anonymous':user_info['guest']=='1',
'is_authenticated':user_info['guest']=='0',
'email':user_info['email'],
'group':user_info['group'],
'nickname':user_info['nickname']})
client.http_context({'url':req.full_uri,
'remote_ip':user_info['remote_ip'],
'agent':user_info['agent'],
'referer':user_info['referer'],
'method':req.method,
'query_string':req.args,
'headers':dict(req.headers_in),
'https':req.is_https(),
# Encode thanks to SentryEncoder to let
# data intact for the invenio serializer.
#
# Indeed req.environ can contain C-Object which are not all