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

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). The metadata field uses a read-only JSON editor (django-json-widget is installed and registered automatically).

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

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-1.0.0.tar.gz (10.5 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-1.0.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file django_actlog-1.0.0.tar.gz.

File metadata

  • Download URL: django_actlog-1.0.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_actlog-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bada342918f3f8bcef9543a8a9627469cd6cd1cca940def95f082f61f058a746
MD5 63b6962ec74f33ff593ae85316241b2d
BLAKE2b-256 b4ad580ac11ee9993bde9a8e86b16bc0337f49285267489d2fd350aeaf7a38fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_actlog-1.0.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-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: django_actlog-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 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-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0df0865ff1fca062de5288658c90353d69e4d9b900ebebe9d5713e167382020c
MD5 1657af735c5ddc4fc437affdc0d40911
BLAKE2b-256 006563cf1bb4794f13aed57632fd9dcc2dfc75df9f8691d9657a5e1ac6d64c5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_actlog-1.0.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