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.

89 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 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. ODOO_USER_EXCEPTIONS = [
  27. 'odoo.exceptions.AccessDenied',
  28. 'odoo.exceptions.AccessError',
  29. 'odoo.exceptions.DeferredException',
  30. 'odoo.exceptions.MissingError',
  31. 'odoo.exceptions.RedirectWarning',
  32. 'odoo.exceptions.UserError',
  33. 'odoo.exceptions.ValidationError',
  34. 'odoo.exceptions.Warning',
  35. 'odoo.exceptions.except_orm',
  36. ]
  37. DEFAULT_IGNORED_EXCEPTIONS = ','.join(ODOO_USER_EXCEPTIONS)
  38. PROCESSORS = (
  39. 'raven.processors.SanitizePasswordsProcessor',
  40. 'odoo.addons.sentry.logutils.SanitizeOdooCookiesProcessor',
  41. )
  42. DEFAULT_PROCESSORS = ','.join(PROCESSORS)
  43. EXCLUDE_LOGGERS = (
  44. 'werkzeug',
  45. )
  46. DEFAULT_EXCLUDE_LOGGERS = ','.join(EXCLUDE_LOGGERS)
  47. DEFAULT_TRANSPORT = 'threaded'
  48. def select_transport(name=DEFAULT_TRANSPORT):
  49. return {
  50. 'requests_synchronous': raven.transport.RequestsHTTPTransport,
  51. 'requests_threaded': raven.transport.ThreadedRequestsHTTPTransport,
  52. 'synchronous': raven.transport.HTTPTransport,
  53. 'threaded': raven.transport.ThreadedHTTPTransport,
  54. }.get(name, DEFAULT_TRANSPORT)
  55. def get_sentry_options():
  56. return [
  57. SentryOption('dsn', '', str.strip),
  58. SentryOption('install_sys_hook', False, None),
  59. SentryOption('transport', DEFAULT_TRANSPORT, select_transport),
  60. SentryOption('include_paths', '', split_multiple),
  61. SentryOption('exclude_paths', '', split_multiple),
  62. SentryOption('machine', defaults.NAME, None),
  63. SentryOption('auto_log_stacks', defaults.AUTO_LOG_STACKS, None),
  64. SentryOption('capture_locals', defaults.CAPTURE_LOCALS, None),
  65. SentryOption('string_max_length', defaults.MAX_LENGTH_STRING, None),
  66. SentryOption('list_max_length', defaults.MAX_LENGTH_LIST, None),
  67. SentryOption('site', None, None),
  68. SentryOption('include_versions', True, None),
  69. SentryOption(
  70. 'ignore_exceptions', DEFAULT_IGNORED_EXCEPTIONS, split_multiple),
  71. SentryOption('processors', DEFAULT_PROCESSORS, split_multiple),
  72. SentryOption('environment', None, None),
  73. ]