A module that provides django-specific resilient logger module.
Project description
Table of Contents generated with DocToc
Logger that ensures that logs sent out to external service.
django-resilient-logger is a logger module that stores logs in local DB and synchronizes those with external log target.
If for some reason synchronization to external service does not work at the given time, it will retry it at later time.
Management tasks require an external cron trigger.
Cron triggers are designed to be run in following schedule:
submit_unsent_entriesonce in every 15 minutes.clear_sent_entriesonce a month.
To manually trigger the scheduled tasks, one can run commands:
python ./manage.py submit_unsent_entries
python ./manage.py clear_sent_entries
Adding django-resilient-logger to your Django project
Add django-resilient-logger in your project"s dependencies.
Adding django-resilient-logger to Django apps
To install this logger, append resilient_logger to INSTALLED_APPS in settings.py:
INSTALLED_APPS = (
"resilient_logger"
...
)
Configuring django-resilient-logger
To configure resilient logger, you must provide config section in your settings.py.
Configuration must contain required origin, environment, sources and targets keys. It also accepts optional keys batch_limit, chunk_size, clear_sent_entries and submit_unsent_entries.
originis the name of the application or unique identifier of it.environmentis the name of the environment where the application is running.sourcesexpects array of objects with propertyclass(full class path) being present. Other properties are ignored.targetsexpects array of objects withclass(full class path) and being present. Others are passed as constructor parameters.
RESILIENT_LOGGER = {
"origin": "NameOfTheApplication",
"environment": env("AUDIT_LOG_ENV"),
"sources": [
{ "class": "resilient_logger.sources.ResilientLogSource" },
{ "class": "resilient_logger.sources.DjangoAuditLogSource" },
],
"targets": [{
"class": "resilient_logger.targets.ElasticsearchLogTarget",
"es_url": env("AUDIT_LOG_ES_URL"),
"es_username": env("AUDIT_LOG_ES_USERNAME"),
"es_password": env("AUDIT_LOG_ES_PASSWORD"),
"es_index": env("AUDIT_LOG_ES_INDEX"),
"required": True
}],
"batch_limit": 5000,
"chunk_size": 500,
"submit_unsent_entries": True,
"clear_sent_entries": True,
}
In addition to the django-resilient-logger specific configuration, one must also configure logger handler to actually use it.
In the sample below the configured logger is called resilient and it will use the RESILIENT_LOGGER configuration above:
LOGGING = {
"handlers": {
"resilient": {
"class": "resilient_logger.handlers.ResilientLogHandler",
...
}
...
},
"loggers": {
"": {
"handlers": ["resilient"],
...
},
...
}
}
Development
Virtual Python environment can be used. For example:
python3 -m venv .venv
source .venv/bin/activate
Install package requirements:
pip install -e .
Install development requirements:
pip install -e ".[all]"
Running tests
pytest
Code format
This project uses Ruff for code formatting and quality checking.
Basic ruff commands:
- lint:
ruff check - apply safe lint fixes:
ruff check --fix - check formatting:
ruff format --check - format:
ruff format
pre-commit can be used to install and
run all the formatting tools as git hooks automatically before a
commit.
Commit message format
New commit messages must adhere to the Conventional Commits specification, and line length is limited to 72 characters.
When pre-commit is in use, commitlint
checks new commit messages for the correct format.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_resilient_logger-2.1.0.tar.gz.
File metadata
- Download URL: django_resilient_logger-2.1.0.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
765560f135c1e38c27bab829d5675d4d6840f8ca9db05c4ab947472d74d6a88d
|
|
| MD5 |
b84817e55913dc49cbadfd33dd05c641
|
|
| BLAKE2b-256 |
e674d55f16bb0364644fd1b0a427c84827d7e03099a90f1749dc6cb4be08f7b6
|
Provenance
The following attestation bundles were made for django_resilient_logger-2.1.0.tar.gz:
Publisher:
publish.yml on City-of-Helsinki/django-resilient-logger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_resilient_logger-2.1.0.tar.gz -
Subject digest:
765560f135c1e38c27bab829d5675d4d6840f8ca9db05c4ab947472d74d6a88d - Sigstore transparency entry: 962435875
- Sigstore integration time:
-
Permalink:
City-of-Helsinki/django-resilient-logger@f7cedeeb621b50cbd09c47969a1dc410c31f8a2a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/City-of-Helsinki
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f7cedeeb621b50cbd09c47969a1dc410c31f8a2a -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_resilient_logger-2.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: django_resilient_logger-2.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 22.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9a76aa2f1056117ba6a44f62e2c6836144da76a3d6322ac4af109fbb50d12c1
|
|
| MD5 |
e143acf98086b89e5af5cb798635902e
|
|
| BLAKE2b-256 |
3e3b62b267e17f7c0b31bc05495851d8c947648cab8368b5c16c8cf2d808f873
|
Provenance
The following attestation bundles were made for django_resilient_logger-2.1.0-py2.py3-none-any.whl:
Publisher:
publish.yml on City-of-Helsinki/django-resilient-logger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_resilient_logger-2.1.0-py2.py3-none-any.whl -
Subject digest:
c9a76aa2f1056117ba6a44f62e2c6836144da76a3d6322ac4af109fbb50d12c1 - Sigstore transparency entry: 962435877
- Sigstore integration time:
-
Permalink:
City-of-Helsinki/django-resilient-logger@f7cedeeb621b50cbd09c47969a1dc410c31f8a2a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/City-of-Helsinki
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f7cedeeb621b50cbd09c47969a1dc410c31f8a2a -
Trigger Event:
push
-
Statement type: