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

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_actlog-0.5.1.tar.gz
  • Upload date:
  • Size: 10.7 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.5.1.tar.gz
Algorithm Hash digest
SHA256 83cee3e355e8e5561c128c2e4401f0c36cb8eefe7df6cf8b7f60632bbfe70212
MD5 bf31614325bf7e8092ecaa1006857032
BLAKE2b-256 a59dde683f5af70222e85dad6617251cf08554c8c437f7e06b03685d7c0a284d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: django_actlog-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 11.1 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.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db77997441f9400cb57eafd3522e32cf5ec7ba23139a646fb6f2ed695f4c2265
MD5 d7e2031e206d93ae3608c0db62301b48
BLAKE2b-256 ac410a7ecaadcdcf29103b6e1b0a69af80ffc5a527c3e8e8b654442bf159edd1

See more details on using hashes here.

Provenance

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