Skip to main content

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

  1. pip install django-actlog
  2. Replace "apps.audit" with "actlog" in INSTALLED_APPS
  3. Keep domain action constants in your project (e.g. apps/core/audit_constants.py)
  4. Update imports:
    • from apps.audit.services import log_eventfrom actlog import log_event
    • from apps.audit.models import AuditLogfrom actlog.models import ActLog
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_actlog-0.4.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_actlog-0.4.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

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

Hashes for django_actlog-0.4.0.tar.gz
Algorithm Hash digest
SHA256 90c4ac6e9be65ee57d0ebe5be2ce6ce9f3f43cc0ef0d3ce3e5de7bf47b40a84f
MD5 3a88df838e34ee603ef8e3cf155a13bb
BLAKE2b-256 0f150b0de3dbce6d01ef4caa37a26c90aaf46989059c07d7fcb4035b7d894d56

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_actlog-0.4.0.tar.gz:

Publisher: publish.yml on HosseinDahaei/django-actlog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for django_actlog-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb93d13494d118a25f6430d80f7a83d8e6bea676d410766555b5e0c41f4024e1
MD5 6d008c900543e0a741d1eeedac9d715e
BLAKE2b-256 c817d407eb7d56699e5c25bb07923cb9e72fde27fbc269cd8a9a2fbd613a9e6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_actlog-0.4.0-py3-none-any.whl:

Publisher: publish.yml on HosseinDahaei/django-actlog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page