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.

88 lines
3.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016-2017 Versada <https://versada.eu/>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. import collections
  5. import logging
  6. import openerp.loglevels
  7. _logger = logging.getLogger(__name__)
  8. try:
  9. import raven
  10. from raven.conf import defaults
  11. except ImportError:
  12. _logger.debug('Cannot import "raven". Please make sure it is installed.')
  13. def split_multiple(string, delimiter=',', strip_chars=None):
  14. '''Splits :param:`string` and strips :param:`strip_chars` from values.'''
  15. if not string:
  16. return []
  17. return [v.strip(strip_chars) for v in string.split(delimiter)]
  18. SentryOption = collections.namedtuple(
  19. 'SentryOption', ['key', 'default', 'converter'])
  20. # Mapping of Odoo logging level -> Python stdlib logging library log level.
  21. LOG_LEVEL_MAP = dict([
  22. (getattr(openerp.loglevels, 'LOG_%s' % x), getattr(logging, x))
  23. for x in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET')
  24. ])
  25. DEFAULT_LOG_LEVEL = 'warn'
  26. ODOO_USER_EXCEPTIONS = [
  27. 'openerp.exceptions.AccessDenied',
  28. 'openerp.exceptions.AccessError',
  29. 'openerp.exceptions.DeferredException',
  30. 'openerp.exceptions.MissingError',
  31. 'openerp.exceptions.RedirectWarning',
  32. 'openerp.exceptions.ValidationError',
  33. 'openerp.exceptions.Warning',
  34. 'openerp.exceptions.except_orm',
  35. ]
  36. DEFAULT_IGNORED_EXCEPTIONS = ','.join(ODOO_USER_EXCEPTIONS)
  37. PROCESSORS = (
  38. 'raven.processors.SanitizePasswordsProcessor',
  39. 'openerp.addons.sentry.logutils.SanitizeOdooCookiesProcessor',
  40. )
  41. DEFAULT_PROCESSORS = ','.join(PROCESSORS)
  42. EXCLUDE_LOGGERS = (
  43. 'werkzeug',
  44. )
  45. DEFAULT_EXCLUDE_LOGGERS = ','.join(EXCLUDE_LOGGERS)
  46. DEFAULT_TRANSPORT = 'threaded'
  47. def select_transport(name=DEFAULT_TRANSPORT):
  48. return {
  49. 'requests_synchronous': raven.transport.RequestsHTTPTransport,
  50. 'requests_threaded': raven.transport.ThreadedRequestsHTTPTransport,
  51. 'synchronous': raven.transport.HTTPTransport,
  52. 'threaded': raven.transport.ThreadedHTTPTransport,
  53. }.get(name, DEFAULT_TRANSPORT)
  54. def get_sentry_options():
  55. return [
  56. SentryOption('dsn', '', str.strip),
  57. SentryOption('install_sys_hook', False, None),
  58. SentryOption('transport', DEFAULT_TRANSPORT, select_transport),
  59. SentryOption('include_paths', '', split_multiple),
  60. SentryOption('exclude_paths', '', split_multiple),
  61. SentryOption('machine', defaults.NAME, None),
  62. SentryOption('auto_log_stacks', defaults.AUTO_LOG_STACKS, None),
  63. SentryOption('capture_locals', defaults.CAPTURE_LOCALS, None),
  64. SentryOption('string_max_length', defaults.MAX_LENGTH_STRING, None),
  65. SentryOption('list_max_length', defaults.MAX_LENGTH_LIST, None),
  66. SentryOption('site', None, None),
  67. SentryOption('include_versions', True, None),
  68. SentryOption(
  69. 'ignore_exceptions', DEFAULT_IGNORED_EXCEPTIONS, split_multiple),
  70. SentryOption('processors', DEFAULT_PROCESSORS, split_multiple),
  71. SentryOption('environment', None, None),
  72. ]