Skip to main content

Generic handler for hooking client side javascript error.

Project description

To install the project from the development:

$ git clone git://github.com/jojax/django-js-error-hook.git
$ cd django-js-error-hook
$ virtualenv env
$ env/bin/python setup.py develop
$ cd demo
$ ../env/bin/python demo/setup.py develop

Then to try the application:

$ demo runserver

Then access: http://localhost:8000/ - the javascript error will be log in your console.

To install the project in production:

$ pip install django-js-error-hook

Add django-js-error-hook to your INSTALLED_APPS settings:

INSTALLED_APPS = (
        ...
    'django.contrib.staticfiles',
    'django_js_error_hook',
            ...
)

If you want to log the error in the console for development:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
        'simple': {
            'format': '\033[22;32m%(levelname)s\033[0;0m %(message)s'
        },
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'simple'
            },
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        'javascript_error': {
            'handlers': ['mail_admins', 'console'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

By default the logger is called “javascript_error”, if you want you can define JAVASCRIPT_ERROR_ID in your settings:

JAVASCRIPT_ERROR_ID = '<your logger name>'

The view will do csrf validation - if for some reason it doesn’t work, set JAVASCRIPT_ERROR_CSRF_EXEMPT to True in your settings.

Then install the urls:

urlpatterns = patterns('',
        ...
    url(r'^js_error_hook/', include('django_js_error_hook.urls')),
    ...
)

In your template, simply add the js_error_hook script:

<script type="text/javascript" src="{% url 'js-error-handler-js' %}"></script>

Now every Javascript error will be logged in your logging error stream. (Mail, Sentry, …)

Have fun and feel free to fork us and give us feedbacks!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-js-error-hook-0.5.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

django_js_error_hook-0.5-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file django-js-error-hook-0.5.tar.gz.

File metadata

File hashes

Hashes for django-js-error-hook-0.5.tar.gz
Algorithm Hash digest
SHA256 698682ed302a6dc42d78b9b3b90e13b71c06488b881ca326b1ecc72fe6d7a88c
MD5 b2d608d487107f0090e1e7b01752aecb
BLAKE2b-256 9d9c81084cddfddedec6cddf1c1ba371ecbe16a045086d083b45ec98ef59d151

See more details on using hashes here.

Provenance

File details

Details for the file django_js_error_hook-0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for django_js_error_hook-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3e04f2a0c346f2c5a9bd7eca63c65fc4cb8c1a7c158d25115342d017e1d5abdc
MD5 d91a6c5e4bd605f9724994053b045969
BLAKE2b-256 f8ae8abd5b19a7754a9512d3ec168f4f9e9ce4d94c98d27188b0466881c7ee74

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page