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. # Copyright 2016-2017 Versada <https://versada.eu/>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. import collections
  4. import logging
  5. import odoo.loglevels
  6. _logger = logging.getLogger(__name__)
  7. try:
  8. import raven
  9. from raven.conf import defaults
  10. except ImportError:
  11. _logger.debug('Cannot import "raven". Please make sure it is installed.')
  12. def split_multiple(string, delimiter=',', strip_chars=None):
  13. '''Splits :param:`string` and strips :param:`strip_chars` from values.'''
  14. if not string:
  15. return []
  16. return [v.strip(strip_chars) for v in string.split(delimiter)]
  17. SentryOption = collections.namedtuple(
  18. 'SentryOption', ['key', 'default', 'converter'])
  19. # Mapping of Odoo logging level -> Python stdlib logging library log level.
  20. LOG_LEVEL_MAP = dict([
  21. (getattr(odoo.loglevels, 'LOG_%s' % x), getattr(logging, x))
  22. for x in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET')
  23. ])
  24. DEFAULT_LOG_LEVEL = 'warn'
  25. ODOO_USER_EXCEPTIONS = [
  26. 'odoo.exceptions.AccessDenied',
  27. 'odoo.exceptions.AccessError',
  28. 'odoo.exceptions.DeferredException',
  29. 'odoo.exceptions.MissingError',
  30. 'odoo.exceptions.RedirectWarning',
  31. 'odoo.exceptions.UserError',
  32. 'odoo.exceptions.ValidationError',
  33. 'odoo.exceptions.Warning',
  34. 'odoo.exceptions.except_orm',
  35. ]
  36. DEFAULT_IGNORED_EXCEPTIONS = ','.join(ODOO_USER_EXCEPTIONS)
  37. PROCESSORS = (
  38. 'raven.processors.SanitizePasswordsProcessor',
  39. 'odoo.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. SentryOption('release', None, None),
  73. ]