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.

76 lines
2.6 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 os
  23. import logging
  24. import cgitb
  25. from openerp.tools import config
  26. from openerp.addons.web.controllers.main import Session
  27. _DEFAULT_LOGGING_LEVEL = logging.ERROR
  28. try:
  29. from .odoo_sentry_client import OdooClient
  30. from .odoo_sentry_handler import OdooSentryHandler
  31. root_logger = logging.root
  32. processors = (
  33. 'raven.processors.SanitizePasswordsProcessor',
  34. 'raven_sanitize_openerp.OpenerpPasswordsProcessor'
  35. )
  36. if config.get(u'sentry_dsn'):
  37. cgitb.enable()
  38. # Get DSN info from config file or ~/.openerp_serverrc (recommended)
  39. dsn = config.get('sentry_dsn')
  40. try:
  41. level = getattr(logging, config.get('sentry_logging_level'))
  42. except (AttributeError, TypeError):
  43. level = _DEFAULT_LOGGING_LEVEL
  44. # Create Client
  45. client = OdooClient(
  46. dsn=dsn,
  47. processors=processors,
  48. )
  49. handler = OdooSentryHandler(client, level=level)
  50. root_logger.addHandler(handler)
  51. else:
  52. msg = u"Sentry DSN not defined in config file"
  53. if os.environ.get('OCA_CI'):
  54. # don't fail the build on runbot for this
  55. root_logger.info(msg)
  56. else:
  57. root_logger.warn(msg)
  58. client = None
  59. # Inject sentry_activated to session to display error message or not
  60. old_session_info = Session.session_info
  61. def session_info(self, req):
  62. res = old_session_info(self, req)
  63. res['sentry_activated'] = bool(client)
  64. return res
  65. Session.session_info = session_info
  66. except ImportError:
  67. pass