<commit_before>Django
======

.. default-domain:: py

`Django <http://djangoproject.com/>`_ is arguably Python's most popular web
framework.  Support is built into Raven but needs some configuration.  While
older versions of Django will likely work, officially only version 1.4 and
newer are supported.

Setup
-----

Using the Django integration is as simple as adding
:mod:`raven.contrib.django.raven_compat` to your installed apps::

    INSTALLED_APPS = (
        'raven.contrib.django.raven_compat',
    )

.. note:: This causes Raven to install a hook in Django that will
          automatically report uncaught exceptions.

Additional settings for the client are configured using the
``RAVEN_CONFIG`` dictionary::

    import raven

    RAVEN_CONFIG = {
        'dsn': '___DSN___',
        # If you are using git, you can also automatically configure the
        # release based on the git info.
        'release': raven.fetch_git_sha(os.path.dirname(__file__)),
    }

Once you've configured the client, you can test it using the standard Django
management interface::

    python manage.py raven test

You'll be referencing the client slightly differently in Django as well::

    from raven.contrib.django.raven_compat.models import client

    client.captureException()


Using with Raven.js
-------------------

A Django template tag is provided to render a proper public DSN inside
your templates, you must first load ``raven``:

.. sourcecode:: django

    {% load raven %}

Inside your template, you can now use:

.. sourcecode:: html+django

    <script>Raven.config('{% sentry_public_dsn %}').install()</script>

By default, the DSN is generated in a protocol relative fashion, e.g.
``//public@example.com/1``. If you need a specific protocol, you can
override:

.. sourcecode:: html+django

    {% sentry_public_dsn 'https' %}

.. sentry:edition:: hosted, on-premise

   See the :doc:`Raven.js documentation <../../../clients/javascript/index>`
   for more information.


Integration with :mod:`logging`
-------------------------------

To integrate with the standard library's :mod:`logging` module the
following config can be used::

    LOGGING = {
        'version': 1,
        'disable_existing_loggers': True,
        'root': {
            'level': 'WARNING',
            'handlers': ['sentry'],
        },
        'formatters': {
            'verbose': {
                'format': '%(levelname)s %(asctime)s %(module)s '
                          '%(process)d %(thread)d %(message)s'
            },
        },
        'handlers': {
            'sentry': {
                'level': 'ERROR',
                'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
                'tags': {'custom-tag': 'x'},
            },
            'console': {
                'level': 'DEBUG',
                'class': 'logging.StreamHandler',
                'formatter': 'verbose'
            }
        },
        'loggers': {
            'django.db.backends': {
                'level': 'ERROR',
                'handlers': ['console'],
                'propagate': False,
            },
            'raven': {
                'level': 'DEBUG',
                'handlers': ['console'],
                'propagate': False,
            },
            'sentry.errors': {
                'level': 'DEBUG',
                'handlers': ['console'],<commit_msg>Be more explicit that LOGGING integration only captures ERROR<commit_after>Django
======

.. default-domain:: py

`Django <http://djangoproject.com/>`_ is arguably Python's most popular web
framework.  Support is built into Raven but needs some configuration.  While
older versions of Django will likely work, officially only version 1.4 and
newer are supported.

Setup
-----

Using the Django integration is as simple as adding
:mod:`raven.contrib.django.raven_compat` to your installed apps::

    INSTALLED_APPS = (
        'raven.contrib.django.raven_compat',
    )

.. note:: This causes Raven to install a hook in Django that will
          automatically report uncaught exceptions.

Additional settings for the client are configured using the
``RAVEN_CONFIG`` dictionary::

    import raven

    RAVEN_CONFIG = {
        'dsn': '___DSN___',
        # If you are using git, you can also automatically configure the
        # release based on the git info.
        'release': raven.fetch_git_sha(os.path.dirname(__file__)),
    }

Once you've configured the client, you can test it using the standard Django
management interface::

    python manage.py raven test

You'll be referencing the client slightly differently in Django as well::

    from raven.contrib.django.raven_compat.models import client

    client.captureException()


Using with Raven.js
-------------------

A Django template tag is provided to render a proper public DSN inside
your templates, you must first load ``raven``:

.. sourcecode:: django

    {% load raven %}

Inside your template, you can now use:

.. sourcecode:: html+django

    <script>Raven.config('{% sentry_public_dsn %}').install()</script>

By default, the DSN is generated in a protocol relative fashion, e.g.
``//public@example.com/1``. If you need a specific protocol, you can
override:

.. sourcecode:: html+django

    {% sentry_public_dsn 'https' %}

.. sentry:edition:: hosted, on-premise

   See the :doc:`Raven.js documentation <../../../clients/javascript/index>`
   for more information.


Integration with :mod:`logging`
-------------------------------

To integrate with the standard library's :mod:`logging` module, and send all
ERROR and above messages to sentry, the following config can be used::

    LOGGING = {
        'version': 1,
        'disable_existing_loggers': True,
        'root': {
            'level': 'WARNING',
            'handlers': ['sentry'],
        },
        'formatters': {
            'verbose': {
                'format': '%(levelname)s %(asctime)s %(module)s '
                          '%(process)d %(thread)d %(message)s'
            },
        },
        'handlers': {
            'sentry': {
                'level': 'ERROR', # To capture more than ERROR, change to WARNING, INFO, etc.
                'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
                'tags': {'custom-tag': 'x'},
            },
            'console': {
                'level': 'DEBUG',
                'class': 'logging.StreamHandler',
                'formatter': 'verbose'
            }
        },
        'loggers': {
            'django.db.backends': {
                'level': 'ERROR',
                'handlers': ['console'],
                'propagate': False,
            },
            'raven': {
                'level': 'DEBUG',
                'handlers': ['console'],
                'propagate': False,
            },
            'sentry.errors': {
                'level': 'DEBUG',
                'handlers': ['console'],
{'fraction_non_alphanumeric': 0.13367052023121387, 'fraction_numerical': 0.0011560693641618498, 'mean_word_length': 2.1345108695652173, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3801485', 'n_tokens_mistral': 1977, 'n_tokens_neox': 1842, 'n_words': 602}