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.

84 lines
2.8 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 odoo.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(odoo.loglevels, 'LOG_%s' % x), getattr(logging, x))
  23. for x in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET')
  24. ])
  25. DEFAULT_LOG_LEVEL = 'warn'
  26. DEFAULT_TRANSPORT = 'threaded'
  27. TRANSPORT_CLASS_MAP = {
  28. 'requests_synchronous': raven.transport.RequestsHTTPTransport,
  29. 'requests_threaded': raven.transport.ThreadedRequestsHTTPTransport,
  30. 'synchronous': raven.transport.HTTPTransport,
  31. 'threaded': raven.transport.ThreadedHTTPTransport,
  32. }
  33. ODOO_USER_EXCEPTIONS = [
  34. 'odoo.exceptions.AccessDenied',
  35. 'odoo.exceptions.AccessError',
  36. 'odoo.exceptions.DeferredException',
  37. 'odoo.exceptions.MissingError',
  38. 'odoo.exceptions.RedirectWarning',
  39. 'odoo.exceptions.UserError',
  40. 'odoo.exceptions.ValidationError',
  41. 'odoo.exceptions.Warning',
  42. 'odoo.exceptions.except_orm',
  43. ]
  44. DEFAULT_IGNORED_EXCEPTIONS = ','.join(ODOO_USER_EXCEPTIONS)
  45. PROCESSORS = (
  46. 'raven.processors.SanitizePasswordsProcessor',
  47. 'odoo.addons.sentry.logutils.SanitizeOdooCookiesProcessor',
  48. )
  49. DEFAULT_PROCESSORS = ','.join(PROCESSORS)
  50. EXCLUDE_LOGGERS = (
  51. 'werkzeug',
  52. )
  53. DEFAULT_EXCLUDE_LOGGERS = ','.join(EXCLUDE_LOGGERS)
  54. SENTRY_OPTIONS = [
  55. SentryOption('dsn', '', str.strip),
  56. SentryOption('install_sys_hook', False, None),
  57. SentryOption('transport', DEFAULT_TRANSPORT, TRANSPORT_CLASS_MAP.get),
  58. SentryOption('include_paths', '', split_multiple),
  59. SentryOption('exclude_paths', '', split_multiple),
  60. SentryOption('machine', defaults.NAME, None),
  61. SentryOption('auto_log_stacks', defaults.AUTO_LOG_STACKS, None),
  62. SentryOption('capture_locals', defaults.CAPTURE_LOCALS, None),
  63. SentryOption('string_max_length', defaults.MAX_LENGTH_STRING, None),
  64. SentryOption('list_max_length', defaults.MAX_LENGTH_LIST, None),
  65. SentryOption('site', None, None),
  66. SentryOption('include_versions', True, None),
  67. SentryOption(
  68. 'ignore_exceptions', DEFAULT_IGNORED_EXCEPTIONS, split_multiple),
  69. SentryOption('processors', DEFAULT_PROCESSORS, split_multiple),
  70. SentryOption('environment', None, None),
  71. ]