Skip to content

Commit 957bda3

Browse files
committed
feat: use django-resilient-logger for audit logging
Refs: PT-1967
1 parent c9060e5 commit 957bda3

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

palvelutarjotin/auditlog_settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"django_ilmoitin.notificationtemplatetranslation", # system model
3535
"occurrences.language", # unimportant and causes lots of issues with factory
3636
"verification_token.verificationtoken", # system model
37+
"resilient_logger.resilientlogentry", # resilient log entries
3738
)
3839

3940
# Configure models registration and other behaviours.

palvelutarjotin/settings.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@
104104
LOGIN_REDIRECT_URL=(str, "/admin/"),
105105
LOGOUT_REDIRECT_URL=(str, "/admin/"),
106106
OPENSHIFT_BUILD_COMMIT=(str, ""),
107+
# Resilient logger config
108+
AUDIT_LOG_ENV=(str, ""),
109+
AUDIT_LOG_ES_URL=(str, ""),
110+
AUDIT_LOG_ES_INDEX=(str, ""),
111+
AUDIT_LOG_ES_USERNAME=(str, ""),
112+
AUDIT_LOG_ES_PASSWORD=(str, ""),
107113
)
108114

109115
if os.path.exists(env_file):
@@ -242,6 +248,7 @@ def sentry_traces_sampler(sampling_context: SamplingContext) -> float:
242248
"django_admin_listfilter_dropdown",
243249
"auditlog",
244250
"auditlog_extra",
251+
"resilient_logger",
245252
"health_check",
246253
# local apps under this line
247254
"custom_health_checks",
@@ -571,3 +578,27 @@ def sentry_traces_sampler(sampling_context: SamplingContext) -> float:
571578

572579
# Load auditlog settings
573580
from palvelutarjotin.auditlog_settings import * # noqa: E402, F403
581+
582+
RESILIENT_LOGGER = {
583+
"origin": "kultus-api",
584+
"environment": env("AUDIT_LOG_ENV"),
585+
"sources": [
586+
{
587+
"class": "resilient_logger.sources.DjangoAuditLogSource",
588+
}
589+
],
590+
"targets": [
591+
{
592+
"class": "resilient_logger.targets.ElasticsearchLogTarget",
593+
"es_url": env("AUDIT_LOG_ES_URL"),
594+
"es_username": env("AUDIT_LOG_ES_USERNAME"),
595+
"es_password": env("AUDIT_LOG_ES_PASSWORD"),
596+
"es_index": env("AUDIT_LOG_ES_INDEX"),
597+
"required": True,
598+
}
599+
],
600+
"batch_limit": 5000,
601+
"chunk_size": 500,
602+
"submit_unsent_entries": True,
603+
"clear_sent_entries": True,
604+
}

requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ django-helusers
1414
django-ilmoitin
1515
django-logger-extra
1616
django-parler
17+
django-resilient-logger
1718
django-utils-six
1819
drf-spectacular
1920
factory-boy

requirements.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ certifi==2025.10.5 \
3434
--hash=sha256:47c09d31ccf2acf0be3f701ea53595ee7e0b8fa08801c6624be771df09ae7b43
3535
# via
3636
# -r requirements.in
37+
# elastic-transport
3738
# requests
3839
# sentry-sdk
3940
cffi==2.0.0 \
@@ -295,6 +296,7 @@ django==5.2.9 \
295296
# django-logger-extra
296297
# django-mailer
297298
# django-parler
299+
# django-resilient-logger
298300
# djangorestframework
299301
# drf-oidc-auth
300302
# drf-spectacular
@@ -370,6 +372,10 @@ django-parler==2.3 \
370372
# via
371373
# -r requirements.in
372374
# django-ilmoitin
375+
django-resilient-logger==1.2.0 \
376+
--hash=sha256:76eb93d30219139cfe0e3d29013b6199f6a0f50642ba15e481b69ca20f4ee0d6 \
377+
--hash=sha256:a7307af5523ffb6deb432c1310f6d97b1a40551ae2ae2cde652eb5b1c265e457
378+
# via -r requirements.in
373379
django-utils-six==2.0 \
374380
--hash=sha256:4ef9d20de679a5b2448429476452493661fe08f23d6e788a8e9816ec05e3c5b0 \
375381
--hash=sha256:8f0e77289d911069a6a15bab5a25ccf2c0fcb8fc4177461dd17470cfdeb94aa6
@@ -393,6 +399,14 @@ ecdsa==0.19.1 \
393399
--hash=sha256:30638e27cf77b7e15c4c4cc1973720149e1033827cfd00661ca5c8cc0cdb24c3 \
394400
--hash=sha256:478cba7b62555866fcb3bb3fe985e06decbdb68ef55713c4e5ab98c57d508e61
395401
# via python-jose
402+
elastic-transport==8.17.1 \
403+
--hash=sha256:192718f498f1d10c5e9aa8b9cf32aed405e469a7f0e9d6a8923431dbb2c59fb8 \
404+
--hash=sha256:5edef32ac864dca8e2f0a613ef63491ee8d6b8cfb52881fa7313ba9290cac6d2
405+
# via elasticsearch8
406+
elasticsearch8==8.19.3 \
407+
--hash=sha256:4b52e59e68aea6f59bf37c28f6f4512333302dd8a52e26c17d0f10c076d833a1 \
408+
--hash=sha256:7effe95b360241b6d56ef68219037a90ad0f56723614db54bbe57d33058402f4
409+
# via django-resilient-logger
396410
executing==2.2.1 \
397411
--hash=sha256:3632cc370565f6648cc328b32435bd120a1e4ebb20c77e3fdde9a13cd1e533c4 \
398412
--hash=sha256:760643d3452b4d777d295bb167ccc74c64a81df23fb5e08eff250c425a4b2017
@@ -650,6 +664,7 @@ python-dateutil==2.9.0.post0 \
650664
--hash=sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427
651665
# via
652666
# django-auditlog
667+
# elasticsearch8
653668
# graphene
654669
python-jose==3.5.0 \
655670
--hash=sha256:abd1202f23d34dfad2c3d28cb8617b90acf34132c7afd60abd0b0b7d3cb55771 \
@@ -959,6 +974,7 @@ typing-extensions==4.15.0 \
959974
--hash=sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466 \
960975
--hash=sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548
961976
# via
977+
# elasticsearch8
962978
# graphene
963979
# psycopg
964980
# referencing
@@ -976,6 +992,7 @@ urllib3==2.6.3 \
976992
# via
977993
# -r requirements.in
978994
# django-anymail
995+
# elastic-transport
979996
# requests
980997
# sentry-sdk
981998
uwsgi==2.0.30 \

0 commit comments

Comments
 (0)