diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index d4d41c1..9b6a086 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -1,37 +1,37 @@ -name: code coverage - -on: - push: - branches: - - master - -jobs: - codecov: - name: Code coverage - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: Set up Python 3.8 - uses: actions/setup-python@v1 - with: - python-version: 3.8 - - name: Install poetry - run: | - python -m pip install --upgrade pip - pip install poetry - - name: Install dependencies - run: | - poetry install - - name: Test with pytest - run: | - poetry run pytest --cov=js_logger --verbose --color=yes --assert=plain --cov-report=xml - poetry run coverage report - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 - with: - token: ${{ secrets.CODECOV_TOKEN }} - file: ./coverage.xml - flags: unittests - name: codecov-umbrella - yml: ./codecov.yml - fail_ci_if_error: true +#name: code coverage +# +#on: +# push: +# branches: +# - master +# +#jobs: +# codecov: +# name: Code coverage +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@master +# - name: Set up Python 3.8 +# uses: actions/setup-python@v1 +# with: +# python-version: 3.8 +# - name: Install poetry +# run: | +# python -m pip install --upgrade pip +# pip install poetry +# - name: Install dependencies +# run: | +# poetry install +# - name: Test with pytest +# run: | +# poetry run pytest --cov=js_logger --verbose --color=yes --assert=plain --cov-report=xml +# poetry run coverage report +# - name: Upload coverage to Codecov +# uses: codecov/codecov-action@v1 +# with: +# token: ${{ secrets.CODECOV_TOKEN }} +# file: ./coverage.xml +# flags: unittests +# name: codecov-umbrella +# yml: ./codecov.yml +# fail_ci_if_error: true diff --git a/README.rst b/README.rst index c3bb9cc..8011eb3 100644 --- a/README.rst +++ b/README.rst @@ -12,29 +12,38 @@ Django Javascript Logger :target: https://pypi.python.org/pypi/django-js-logger .. image:: https://codecov.io/gh/sondrelg/django-js-logger/branch/master/graph/badge.svg + :alt: Code coverage :target: https://codecov.io/gh/sondrelg/django-js-logger/ .. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :alt: Code style black :target: https://pypi.org/project/django-swagger-tester/ .. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white + :alt: Pre-commit enabled :target: https://github.com/pre-commit/pre-commit +.. image:: http://www.mypy-lang.org/static/mypy_badge.svg + :alt: Checked with mypy + :target: http://mypy-lang.org/ + | -Simple Django app for logging Javascript's ``console.log`` logs to Django. +This is a very simple Django app for forwarding console logs and console errors to dedicated Django loggers. + +Useful for catching Javascript errors that are not logged by Django natively and would otherwise only be logged to the client's console. Can be particularly useful if you have JavaScript running on top of our server-side rendered views. -Useful for catching Javascript errors that are not logged by Django natively and would otherwise only be logged to the client's console. +The app works by posting *all relevant events* to an internal Django API, which logs them to one of two loggers. Not sure what impact this has on an apps performance, but it likely should not run anywhere near performance-sensitive production environments. Primarily this is intended to be a debugging aid. -The app works by posting all logs to an internal API; because of this, it should likely not be run in performance-sensitive production environments. +A flowchart of the app's structure looks something like this: .. raw:: html

- flowchart + flowchart

-If you want to implement this package, and require extra functionality please feel free to commit an issue or a PR. Otherwise, this currently does exactly what I need it to do, and I likely won't change it. +The package is open to contributions. Installation ------------ @@ -43,10 +52,14 @@ Installing with pip:: pip install django-js-logger +Installing with poetry:: + + poetry add django-js-logger + Quick start ----------- -1. Add "js_logger" to your INSTALLED_APPS settings:: +1. Add ``js_logger`` to your INSTALLED_APPS settings:: INSTALLED_APPS = [ ... @@ -57,61 +70,15 @@ Quick start path('js-logs/', include('js_logger.urls')), -3. Add the required static file to your project by running ``manage.py collectstatic``, or by manually adding the following code to ``/js-logging/js-logging.html``:: - - +4. Add the required static file to your project by running ``manage.py collectstatic``. This should add a folder, ``django_js_logger`` with the file ``logger.js``. If this is not the case, you can copy the file manually from the demo project above. +5. Import ``logger.js`` in the views you wish to log from by adding a JS import to your templates:: - -4. Include the template where ever you wish for logs to be sent in from (perhaps a base or header template):: - - - ... - {% include "js-logging/js-logging.html" %} - ... - - - -5. Add ``console.log`` as a logger in your logging configuration:: - - 'console.log': { - 'level': 'INFO', - ... - }, - -Note: This package will log all `console.log` calls in your frontend as ``INFO`` logs, and will log javascript errors as ``ERROR`` logs. + diff --git a/demo/settings.py b/demo/settings.py index d0e516e..693d76f 100644 --- a/demo/settings.py +++ b/demo/settings.py @@ -75,8 +75,6 @@ 'django': {'handlers': ['console'], 'level': 'INFO', 'propagate': True}, 'django.server': {'handlers': ['console'], 'level': 'INFO', 'propagate': False}, 'django.request': {'handlers': ['console'], 'level': 'DEBUG', 'propagate': False}, - 'console_log': {'handlers': ['console'], 'level': JS_LOGGER['CONSOLE_LOG_LEVEL']}, - 'console_error': {'handlers': ['console'], 'level': JS_LOGGER['CONSOLE_ERROR_LEVEL']}, }, } diff --git a/docs/img/flowchart.png b/docs/img/flowchart.png index 31ceca6..395791a 100644 Binary files a/docs/img/flowchart.png and b/docs/img/flowchart.png differ