django-logger-extra 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. django_logger_extra-1.0.0/.commitlintrc.mjs +43 -0
  2. django_logger_extra-1.0.0/.github/dependabot.yml +10 -0
  3. django_logger_extra-1.0.0/.github/workflows/pre-commit.yml +27 -0
  4. django_logger_extra-1.0.0/.github/workflows/publish.yml +56 -0
  5. django_logger_extra-1.0.0/.github/workflows/test.yml +43 -0
  6. django_logger_extra-1.0.0/.gitignore +172 -0
  7. django_logger_extra-1.0.0/.pre-commit-config.yaml +47 -0
  8. django_logger_extra-1.0.0/.release-please-manifest.json +3 -0
  9. django_logger_extra-1.0.0/CHANGELOG.md +9 -0
  10. django_logger_extra-1.0.0/CODEOWNERS +1 -0
  11. django_logger_extra-1.0.0/LICENSE +21 -0
  12. django_logger_extra-1.0.0/PKG-INFO +221 -0
  13. django_logger_extra-1.0.0/README.md +169 -0
  14. django_logger_extra-1.0.0/logger_extra/__init__.py +0 -0
  15. django_logger_extra-1.0.0/logger_extra/apps.py +21 -0
  16. django_logger_extra-1.0.0/logger_extra/extras/__init__.py +0 -0
  17. django_logger_extra-1.0.0/logger_extra/extras/django_auditlog.py +66 -0
  18. django_logger_extra-1.0.0/logger_extra/filter.py +35 -0
  19. django_logger_extra-1.0.0/logger_extra/formatter.py +25 -0
  20. django_logger_extra-1.0.0/logger_extra/logger_context.py +23 -0
  21. django_logger_extra-1.0.0/logger_extra/middleware.py +41 -0
  22. django_logger_extra-1.0.0/logger_extra/utils.py +82 -0
  23. django_logger_extra-1.0.0/pyproject.toml +152 -0
  24. django_logger_extra-1.0.0/release-please-config.json +27 -0
  25. django_logger_extra-1.0.0/sonar-project.properties +6 -0
  26. django_logger_extra-1.0.0/tests/__init__.py +0 -0
  27. django_logger_extra-1.0.0/tests/manage.py +23 -0
  28. django_logger_extra-1.0.0/tests/models.py +14 -0
  29. django_logger_extra-1.0.0/tests/settings.py +68 -0
  30. django_logger_extra-1.0.0/tests/test_django_auditlog.py +39 -0
  31. django_logger_extra-1.0.0/tests/test_extras.py +23 -0
  32. django_logger_extra-1.0.0/tests/test_logger_context.py +29 -0
  33. django_logger_extra-1.0.0/tests/test_middleware.py +103 -0
  34. django_logger_extra-1.0.0/tests/urls.py +10 -0
  35. django_logger_extra-1.0.0/tests/views.py +32 -0
@@ -0,0 +1,43 @@
1
+ export default {
2
+ extends: [
3
+ '@commitlint/config-conventional'
4
+ ],
5
+ ignores: [
6
+ (message) => message.includes('Signed-off-by: dependabot[bot]'),
7
+ (message) => message.includes('Signed-off-by: sol-office-file-synchronization[bot]')
8
+ ],
9
+ rules: {
10
+ 'header-max-length': [
11
+ 2,
12
+ 'always',
13
+ 72
14
+ ],
15
+ 'body-max-line-length': [
16
+ 2,
17
+ 'always',
18
+ 72
19
+ ],
20
+ 'body-leading-blank': [
21
+ 2,
22
+ 'always'
23
+ ],
24
+ 'type-enum': [
25
+ 2,
26
+ 'always',
27
+ [
28
+ 'build',
29
+ 'chore',
30
+ 'ci',
31
+ 'deps',
32
+ 'docs',
33
+ 'feat',
34
+ 'fix',
35
+ 'perf',
36
+ 'refactor',
37
+ 'revert',
38
+ 'style',
39
+ 'test'
40
+ ]
41
+ ]
42
+ }
43
+ };
@@ -0,0 +1,10 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "pip"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "daily"
7
+ commit-message:
8
+ prefix: "deps"
9
+ # Disable version updates and only allow security updates
10
+ open-pull-requests-limit: 0
@@ -0,0 +1,27 @@
1
+ name: Run pre-commit hooks
2
+
3
+ env:
4
+ DEFAULT_PYTHON: "3.10"
5
+
6
+ on:
7
+ push:
8
+ branches: [ main ]
9
+ pull_request:
10
+ branches: [ main ]
11
+
12
+ jobs:
13
+ pre-commit:
14
+ name: Run pre-commit hooks
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - name: Checkout
19
+ uses: actions/checkout@v4
20
+
21
+ - name: Setup Python 3.10
22
+ uses: actions/setup-python@v5
23
+ with:
24
+ python-version: "3.10"
25
+
26
+ - name: Run pre-commit
27
+ uses: pre-commit/action@v3.0.1
@@ -0,0 +1,56 @@
1
+ name: Create release & publish to PyPI
2
+ # If ran manually, e.g. with ref set to "refs/tags/v1.2.3", set the run name to "Publish refs/tags/v1.2.3".
3
+ run-name: ${{ inputs.ref && format('Publish {0}', inputs.ref) || null }}
4
+
5
+ on:
6
+ push:
7
+ branches:
8
+ - main
9
+ # Run daily to keep the release PR date current
10
+ schedule:
11
+ - cron: '1 0 * * *'
12
+ workflow_dispatch:
13
+ inputs:
14
+ ref:
15
+ description: "The branch, tag or SHA to publish."
16
+ required: true
17
+ type: string
18
+
19
+ jobs:
20
+ release-please:
21
+ uses: City-of-Helsinki/.github/.github/workflows/release-please.yml@main
22
+ permissions:
23
+ contents: write
24
+ pull-requests: write
25
+ with:
26
+ include-component-in-tag: false
27
+
28
+ build:
29
+ needs:
30
+ - release-please
31
+ uses: City-of-Helsinki/.github/.github/workflows/build-python-dists.yml@main
32
+ with:
33
+ ref: ${{ inputs.ref }}
34
+ # Run build job if a release was created or a ref was specified (i.e. workflow was invoked manually)
35
+ if: ${{ needs.release-please.outputs.release_created || inputs.ref }}
36
+
37
+ publish-to-pypi:
38
+ name: Publish to PyPI
39
+ runs-on: ubuntu-latest
40
+ needs:
41
+ - build
42
+ # Run publish job if an artifact was uploaded
43
+ if: ${{ needs.build.outputs.artifact_name }}
44
+ environment:
45
+ name: pypi
46
+ url: https://pypi.org/p/django-logger-extra
47
+ permissions:
48
+ id-token: write # mandatory for trusted publishing
49
+ steps:
50
+ - name: Download all the dists
51
+ uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
52
+ with:
53
+ name: ${{ needs.build.outputs.artifact_name }}
54
+ path: dist/
55
+ - name: Publish distribution to PyPI
56
+ uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
@@ -0,0 +1,43 @@
1
+ name: Run tests
2
+
3
+ env:
4
+ DEFAULT_PYTHON: "3.10"
5
+
6
+ on:
7
+ push:
8
+ branches: [ main ]
9
+ pull_request:
10
+ branches: [ main ]
11
+
12
+ jobs:
13
+ test:
14
+ name: Python ${{ matrix.python_version }}
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ matrix:
18
+ python_version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
19
+
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+
23
+ - name: Set up Python ${{ matrix.python_version }}
24
+ uses: actions/setup-python@v5
25
+ with:
26
+ python-version: ${{ matrix.python_version }}
27
+
28
+ - name: Install hatch
29
+ run: python -m pip install hatch
30
+
31
+ - name: Tests
32
+ run: hatch test -i py=${{ matrix.python_version }} -- --cov=. --cov-report=xml
33
+
34
+ - name: Override coverage report source path for SonarQube Cloud
35
+ if: ${{ matrix.python_version == env.DEFAULT_PYTHON }}
36
+ run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml
37
+
38
+ - name: SonarQube Cloud Scan
39
+ if: ${{ matrix.python_version == env.DEFAULT_PYTHON }}
40
+ uses: SonarSource/sonarqube-scan-action@fd88b7d7ccbaefd23d8f36f73b59db7a3d246602 # v6.0.0
41
+ env:
42
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43
+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
@@ -0,0 +1,172 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # PyPI configuration file
171
+ .pypirc
172
+ .DS_Store
@@ -0,0 +1,47 @@
1
+ default_language_version:
2
+ python: python3
3
+ default_install_hook_types: [pre-commit, commit-msg]
4
+ default_stages: [pre-commit, manual]
5
+ repos:
6
+ - repo: https://github.com/pre-commit/pre-commit-hooks
7
+ rev: v5.0.0
8
+ hooks:
9
+ - id: trailing-whitespace
10
+ - id: end-of-file-fixer
11
+ - id: check-yaml
12
+ - id: check-toml
13
+ - id: check-added-large-files
14
+ # Run pyupgrade and django-upgrade before ruff, as these two might alter
15
+ # the code in a way that requires reformatting.
16
+ - repo: https://github.com/asottile/pyupgrade
17
+ rev: v3.21.0
18
+ hooks:
19
+ - id: pyupgrade
20
+ args: ["--py310-plus"]
21
+ - repo: https://github.com/adamchainz/django-upgrade
22
+ rev: "1.29.1"
23
+ hooks:
24
+ - id: django-upgrade
25
+ args: [--target-version, "4.2"]
26
+ - repo: https://github.com/astral-sh/ruff-pre-commit
27
+ rev: v0.14.2
28
+ hooks:
29
+ # Run the linter.
30
+ - id: ruff-check
31
+ args: [ --fix ]
32
+ # Run the formatter.
33
+ - id: ruff-format
34
+ - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
35
+ rev: v9.22.0
36
+ hooks:
37
+ - id: commitlint
38
+ stages: [commit-msg, manual]
39
+ additional_dependencies: ["@commitlint/config-conventional"]
40
+ - repo: https://github.com/koalaman/shellcheck-precommit
41
+ rev: v0.11.0
42
+ hooks:
43
+ - id: shellcheck
44
+ - repo: https://github.com/thlorenz/doctoc
45
+ rev: v2.2.0
46
+ hooks:
47
+ - id: doctoc
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "1.0.0"
3
+ }
@@ -0,0 +1,9 @@
1
+ <!-- DOCTOC SKIP -->
2
+ # Changelog
3
+
4
+ ## [1.0.0](https://github.com/City-of-Helsinki/django-logger-extra/compare/v0.1.0...v1.0.0) (2025-11-13)
5
+
6
+
7
+ ### Dependencies
8
+
9
+ * Update python and django version support ([c1eccc4](https://github.com/City-of-Helsinki/django-logger-extra/commit/c1eccc4bf013839c9084da0706ba34a1c208de90))
@@ -0,0 +1 @@
1
+ * @City-of-Helsinki/ratkaisutoimiston-backend
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 City of Helsinki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,221 @@
1
+ Metadata-Version: 2.4
2
+ Name: django-logger-extra
3
+ Version: 1.0.0
4
+ Summary: A module that provides extras for logger.
5
+ Project-URL: Homepage, https://github.com/City-of-Helsinki/django-logger-extra
6
+ Project-URL: Issues, https://github.com/City-of-Helsinki/django-logger-extra/issues
7
+ Author-email: City of Helsinki <dev@hel.fi>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: extra tools,logging,plugin extension
11
+ Classifier: Environment :: Web Environment
12
+ Classifier: Framework :: Django
13
+ Classifier: Framework :: Django :: 4.2
14
+ Classifier: Framework :: Django :: 5.1
15
+ Classifier: Framework :: Django :: 5.2
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3 :: Only
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Programming Language :: Python :: 3.14
27
+ Classifier: Topic :: Internet :: WWW/HTTP
28
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
29
+ Requires-Dist: django>=4.2
30
+ Provides-Extra: all
31
+ Requires-Dist: coverage-enable-subprocess; extra == 'all'
32
+ Requires-Dist: coverage[toml]; extra == 'all'
33
+ Requires-Dist: django-auditlog; extra == 'all'
34
+ Requires-Dist: pytest; extra == 'all'
35
+ Requires-Dist: pytest-cov; extra == 'all'
36
+ Requires-Dist: pytest-django; extra == 'all'
37
+ Requires-Dist: pytest-randomly; extra == 'all'
38
+ Requires-Dist: pytest-rerunfailures; extra == 'all'
39
+ Requires-Dist: pytest-xdist[psutil]; extra == 'all'
40
+ Provides-Extra: auditlog
41
+ Requires-Dist: django-auditlog; extra == 'auditlog'
42
+ Provides-Extra: test
43
+ Requires-Dist: coverage-enable-subprocess; extra == 'test'
44
+ Requires-Dist: coverage[toml]; extra == 'test'
45
+ Requires-Dist: pytest; extra == 'test'
46
+ Requires-Dist: pytest-cov; extra == 'test'
47
+ Requires-Dist: pytest-django; extra == 'test'
48
+ Requires-Dist: pytest-randomly; extra == 'test'
49
+ Requires-Dist: pytest-rerunfailures; extra == 'test'
50
+ Requires-Dist: pytest-xdist[psutil]; extra == 'test'
51
+ Description-Content-Type: text/markdown
52
+
53
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
54
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
55
+ **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
56
+
57
+ - [Logger extras for simplified structured logging.](#logger-extras-for-simplified-structured-logging)
58
+ - [Adding django-logger-extra your Django project](#adding-django-logger-extra-your-django-project)
59
+ - [Adding django-resilient-logger Django apps](#adding-django-resilient-logger-django-apps)
60
+ - [Configuring logger formatter in settings.py:](#configuring-logger-formatter-in-settingspy)
61
+ - [Configuring middleware in settings.py:](#configuring-middleware-in-settingspy)
62
+ - [django-auditlog extra context.](#django-auditlog-extra-context)
63
+ - [Logger context usage](#logger-context-usage)
64
+ - [Development](#development)
65
+ - [Running tests](#running-tests)
66
+ - [Code format](#code-format)
67
+ - [Git blame ignore refs](#git-blame-ignore-refs)
68
+ - [Commit message format](#commit-message-format)
69
+
70
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
71
+
72
+ # Logger extras for simplified structured logging.
73
+
74
+ `django-logger-extra` is a collection of logger extras that makes structured logging setup easier.
75
+
76
+ ## Adding django-logger-extra your Django project
77
+
78
+ Add `django-logger-extra` in your project's dependencies.
79
+
80
+ ### Adding django-resilient-logger Django apps
81
+
82
+ To install this logger, add `INSTALLED_APPS` in settings.py:
83
+
84
+ ```python
85
+ INSTALLED_APPS = (
86
+ 'logger_extra',
87
+ ...
88
+ )
89
+ ```
90
+
91
+ ### Configuring logger formatter in settings.py:
92
+ To make use of the JSON formatter it must be configured in setting's LOGGING section.
93
+ Filter is optional and brings `logger_context()` contexts available as logger extras.
94
+
95
+ ```python
96
+ LOGGING = {
97
+ 'filters': {
98
+ 'context': {
99
+ '()': 'logger_extra.filter.LoggerContextFilter',
100
+ }
101
+ ...
102
+ },
103
+ 'formatters': {
104
+ 'json': {
105
+ '()': 'logger_extra.formatter.JSONFormatter',
106
+ }
107
+ ...
108
+ },
109
+ 'handlers': {
110
+ 'console': {
111
+ 'class': 'logging.StreamHandler',
112
+ 'formatter': 'json',
113
+ 'filters': ['context']
114
+ },
115
+ ...
116
+ },
117
+ ...
118
+ }
119
+ ```
120
+
121
+ ### Configuring middleware in settings.py:
122
+ ```python
123
+ MIDDLEWARE = [
124
+ 'logger_extra.middleware.XRequestIdMiddleware',
125
+ ...
126
+ ]
127
+ ```
128
+
129
+ ## django-auditlog extra context.
130
+ This library can also augment django-auditlog's additional_data fields with active context.
131
+ To enable this, optional package `django-auditlog` must be installed and it must be explicitly enabled
132
+ in settings.py file.
133
+ ```python
134
+ LOGGER_EXTRA_AUGMENT_DJANGO_AUDITLOG = True
135
+ ```
136
+
137
+ ## Logger context usage
138
+ Active context can be appended with `logger_context` function. It will return current
139
+ context as resource. The current context can also be read using function `get_logger_context`.
140
+ ```python
141
+ import logging
142
+ from django.http import HttpRequest, JsonResponse
143
+
144
+ from logger_extra.logger_context import logger_context
145
+
146
+ logger = logging.getLogger("audit")
147
+
148
+ def bar():
149
+ with logger_context({ "who": "World" }) as ctx:
150
+ logger.info(f"{ctx['greet']} {ctx['who']}")
151
+
152
+ def foo():
153
+ with logger_context({ "greet": "Hello" }):
154
+ bar()
155
+ return JsonResponse({})
156
+ ```
157
+
158
+ Will result log entry that looks like:
159
+ `{"message": "Hello World", "level": "INFO", "time": "2025-04-14T11:08:22.962222+00:00", "context": {"request_id": "95e787b5-4ce8-46ef-bb6e-31651fc8774b", "greet": "Hello", "who": "World"}}`
160
+ # Development
161
+
162
+ Virtual Python environment can be used. For example:
163
+
164
+ ```bash
165
+ python3 -m venv .venv
166
+ source .venv/bin/activate
167
+ ```
168
+
169
+ Install package requirements:
170
+
171
+ ```bash
172
+ pip install -e .
173
+ ```
174
+
175
+ Install development requirements:
176
+
177
+ ```bash
178
+ pip install -r requirements-test.txt
179
+ ```
180
+
181
+ ## Running tests
182
+
183
+ ```bash
184
+ pytest
185
+ ```
186
+
187
+ ## Code format
188
+
189
+ This project uses [Ruff](https://docs.astral.sh/ruff/) for code formatting and quality checking.
190
+
191
+ Basic `ruff` commands:
192
+
193
+ * lint: `ruff check`
194
+ * apply safe lint fixes: `ruff check --fix`
195
+ * check formatting: `ruff format --check`
196
+ * format: `ruff format`
197
+
198
+ [`pre-commit`](https://pre-commit.com/) can be used to install and
199
+ run all the formatting tools as git hooks automatically before a
200
+ commit.
201
+
202
+
203
+ ## Git blame ignore refs
204
+
205
+ Project includes a `.git-blame-ignore-revs` file for ignoring certain commits from `git blame`.
206
+ This can be useful for ignoring e.g. formatting commits, so that it is more clear from `git blame`
207
+ where the actual code change came from. Configure your git to use it for this project with the
208
+ following command:
209
+
210
+ ```shell
211
+ git config blame.ignoreRevsFile .git-blame-ignore-revs
212
+ ```
213
+
214
+
215
+ ## Commit message format
216
+
217
+ New commit messages must adhere to the [Conventional Commits](https://www.conventionalcommits.org/)
218
+ specification, and line length is limited to 72 characters.
219
+
220
+ When [`pre-commit`](https://pre-commit.com/) is in use, [`commitlint`](https://github.com/conventional-changelog/commitlint)
221
+ checks new commit messages for the correct format.