Browse Source

Merge pull request #98 from savoirfairelinux/sentry_fix

[FIX] Skip init if raven is not available on the system
pull/100/head
Maxime Chambreuil - http://www.savoirfairelinux.com 10 years ago
parent
commit
60d54c4822
  1. 28
      sentry_logger/__init__.py

28
sentry_logger/__init__.py

@ -26,17 +26,17 @@ import cgitb
from openerp.tools import config
from openerp.addons.web.controllers.main import Session
from .odoo_sentry_client import OdooClient
from .odoo_sentry_handler import OdooSentryHandler
try:
from .odoo_sentry_client import OdooClient
from .odoo_sentry_handler import OdooSentryHandler
root_logger = logging.root
root_logger = logging.root
processors = (
processors = (
'raven.processors.SanitizePasswordsProcessor',
'raven_sanitize_openerp.OpenerpPasswordsProcessor'
)
if config.get(u'sentry_dsn'):
)
if config.get(u'sentry_dsn'):
cgitb.enable()
# Get DSN info from config file or ~/.openerp_serverrc (recommended)
dsn = config.get('sentry_dsn')
@ -47,18 +47,18 @@ if config.get(u'sentry_dsn'):
)
handler = OdooSentryHandler(client, level=logging.ERROR)
root_logger.addHandler(handler)
else:
else:
root_logger.warn(u"Sentry DSN not defined in config file")
client = None
# Inject sentry_activated to session to display error message or not
old_session_info = Session.session_info
# Inject sentry_activated to session to display error message or not
old_session_info = Session.session_info
def session_info(self, req):
def session_info(self, req):
res = old_session_info(self, req)
res['sentry_activated'] = bool(client)
return res
Session.session_info = session_info
Session.session_info = session_info
except ImportError:
pass
Loading…
Cancel
Save