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.

70 lines
2.4 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. _DEFAULT_LOGGING_LEVEL = logging.ERROR
  27. try:
  28. from .odoo_sentry_client import OdooClient
  29. from .odoo_sentry_handler import OdooSentryHandler
  30. root_logger = logging.root
  31. processors = (
  32. 'raven.processors.SanitizePasswordsProcessor',
  33. 'raven_sanitize_openerp.OpenerpPasswordsProcessor'
  34. )
  35. if config.get(u'sentry_dsn'):
  36. cgitb.enable()
  37. # Get DSN info from config file or ~/.openerp_serverrc (recommended)
  38. dsn = config.get('sentry_dsn')
  39. try:
  40. level = getattr(logging, config.get('sentry_logging_level'))
  41. except (AttributeError, TypeError):
  42. level = _DEFAULT_LOGGING_LEVEL
  43. # Create Client
  44. client = OdooClient(
  45. dsn=dsn,
  46. processors=processors,
  47. )
  48. handler = OdooSentryHandler(client, level=level)
  49. root_logger.addHandler(handler)
  50. else:
  51. root_logger.warn(u"Sentry DSN not defined in config file")
  52. client = None
  53. # Inject sentry_activated to session to display error message or not
  54. old_session_info = Session.session_info
  55. def session_info(self, req):
  56. res = old_session_info(self, req)
  57. res['sentry_activated'] = bool(client)
  58. return res
  59. Session.session_info = session_info
  60. except ImportError:
  61. pass