Minimal explicit event logging for Django MVPs.
Project description
django-actlog
Minimal, opt-in application event logging for Django MVPs.
Unlike django-auditlog (automatic model change history) or django-easy-audit (automatic CRUD/auth hooks), django-actlog records events only when you explicitly call log_event() with a host-defined action string.
Install
pip install django-actlog
Optional extras:
pip install "django-actlog[admin]" # pretty JSON metadata in Django admin
Add to INSTALLED_APPS and migrate:
INSTALLED_APPS = [
# ...
"actlog",
]
python manage.py migrate actlog
Quick start
Define action constants in your project (not in the library):
# myapp/audit_constants.py
LOGIN_SUCCESS = "LOGIN_SUCCESS"
OTP_SENT = "OTP_SENT"
Log events from your services:
from actlog import log_event, Level
from myapp.audit_constants import LOGIN_SUCCESS, LOGIN_FAILED
def on_login_success(user, request, session):
event = log_event(
LOGIN_SUCCESS,
user=user,
metadata={
"method": "otp",
"session_id": session.id,
"ip": request.META.get("REMOTE_ADDR"),
"user_agent": request.META.get("HTTP_USER_AGENT", ""),
},
)
def on_login_failed(request, username):
log_event(
LOGIN_FAILED,
level=Level.WARNING,
metadata={"username": username, "ip": request.META.get("REMOTE_ADDR")},
)
log_event() persists synchronously and returns the created ActLog instance. Pass any request or domain context via metadata.
Severity is set with level (optional; default INFO). Values mirror Python logging: DEBUG, INFO, WARNING, ERROR, CRITICAL (Level).
Settings
| Setting | Default | Description |
|---|---|---|
ACTLOG_MODEL |
"actlog.ActLog" |
Dotted path to the log model (advanced) |
ACTLOG_USER_RELATED_NAME |
"act_logs" |
related_name on the user FK |
ACTLOG_ACTION_MAX_LENGTH |
64 |
Max length for action strings |
ACTLOG_USER_SEARCH_FIELDS |
("user__email",) |
Admin search lookups for the user FK |
Django admin
Register is automatic. The admin is read-only (no add/delete).
For a JSON editor on the metadata field:
pip install "django-actlog[admin]"
Custom user models: override ACTLOG_USER_SEARCH_FIELDS if user__email does not apply.
Public API
from actlog import log_event, ActLog, Level
from actlog.models import ActLog
from actlog.choices import Level
from actlog.services import log_event
Migrating from an internal apps.audit app
pip install django-actlog- Replace
"apps.audit"with"actlog"inINSTALLED_APPS - Keep domain action constants in your project (e.g.
apps/core/audit_constants.py) - Update imports:
from apps.audit.services import log_event→from actlog import log_eventfrom apps.audit.models import AuditLog→from actlog.models import ActLog
- Remove any
ACTLOG_SYNC,ACTLOG_EMIT_IMMEDIATELY, or Celery task configuration — logging is always synchronous.
v0.1.0 targets new installs. Existing audit_auditlog tables require a custom data migration if you need to preserve history under a new table name (actlog_actlog).
License
MIT
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_actlog-0.4.0.tar.gz.
File metadata
- Download URL: django_actlog-0.4.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90c4ac6e9be65ee57d0ebe5be2ce6ce9f3f43cc0ef0d3ce3e5de7bf47b40a84f
|
|
| MD5 |
3a88df838e34ee603ef8e3cf155a13bb
|
|
| BLAKE2b-256 |
0f150b0de3dbce6d01ef4caa37a26c90aaf46989059c07d7fcb4035b7d894d56
|
Provenance
The following attestation bundles were made for django_actlog-0.4.0.tar.gz:
Publisher:
publish.yml on HosseinDahaei/django-actlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_actlog-0.4.0.tar.gz -
Subject digest:
90c4ac6e9be65ee57d0ebe5be2ce6ce9f3f43cc0ef0d3ce3e5de7bf47b40a84f - Sigstore transparency entry: 2182203611
- Sigstore integration time:
-
Permalink:
HosseinDahaei/django-actlog@95b8d25bd4c2529e45923bbc2851a429a4f07b1e -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/HosseinDahaei
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@95b8d25bd4c2529e45923bbc2851a429a4f07b1e -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_actlog-0.4.0-py3-none-any.whl.
File metadata
- Download URL: django_actlog-0.4.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb93d13494d118a25f6430d80f7a83d8e6bea676d410766555b5e0c41f4024e1
|
|
| MD5 |
6d008c900543e0a741d1eeedac9d715e
|
|
| BLAKE2b-256 |
c817d407eb7d56699e5c25bb07923cb9e72fde27fbc269cd8a9a2fbd613a9e6d
|
Provenance
The following attestation bundles were made for django_actlog-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on HosseinDahaei/django-actlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_actlog-0.4.0-py3-none-any.whl -
Subject digest:
bb93d13494d118a25f6430d80f7a83d8e6bea676d410766555b5e0c41f4024e1 - Sigstore transparency entry: 2182203721
- Sigstore integration time:
-
Permalink:
HosseinDahaei/django-actlog@95b8d25bd4c2529e45923bbc2851a429a4f07b1e -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/HosseinDahaei
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@95b8d25bd4c2529e45923bbc2851a429a4f07b1e -
Trigger Event:
release
-
Statement type: