You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.1 KiB

  1. # -*- coding: utf-8 -*-
  2. ###############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2010 - 2014 Savoir-faire Linux
  6. # (<http://www.savoirfairelinux.com>).
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ###############################################################################
  22. import logging
  23. import cgitb
  24. from openerp.tools import config
  25. from openerp.addons.web.controllers.main import Session
  26. from .odoo_sentry_client import OdooClient
  27. from .odoo_sentry_handler import OdooSentryHandler
  28. root_logger = logging.root
  29. processors = (
  30. 'raven.processors.SanitizePasswordsProcessor',
  31. 'raven_sanitize_openerp.OpenerpPasswordsProcessor'
  32. )
  33. if config.get(u'sentry_dsn'):
  34. cgitb.enable()
  35. # Get DSN info from config file or ~/.openerp_serverrc (recommended)
  36. dsn = config.get('sentry_dsn')
  37. # Create Client
  38. client = OdooClient(
  39. dsn=dsn,
  40. processors=processors,
  41. )
  42. handler = OdooSentryHandler(client, level=logging.ERROR)
  43. root_logger.addHandler(handler)
  44. else:
  45. root_logger.warn(u"Sentry DSN not defined in config file")
  46. client = None
  47. # Inject sentry_activated to session to display error message or not
  48. old_session_info = Session.session_info
  49. def session_info(self, req):
  50. res = old_session_info(self, req)
  51. res['sentry_activated'] = bool(client)
  52. return res
  53. Session.session_info = session_info