Skip to content

Common audit logging library for FastAPI applications. Provides standardized audit trail functionality, activity tracking, and compliance logging for API security and governance requirements.

Notifications You must be signed in to change notification settings

ITlusions/ITL.Fastapi.Common.AuditLog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Audit Logging

Deze README beschrijft hoe je de audit logging functionaliteit in een FastAPI-applicatie kunt gebruiken.

πŸ“Œ Functies

  • βœ… Middleware voor audit logging
  • βœ… Automatische Request*ID en Correlation*ID
  • βœ… Server hostname en applicatieversie in response headers
  • βœ… Aanpasbare auditlog evenementen
  • βœ… Eenvoudig te integreren in bestaande FastAPI-applicaties

πŸ“¦ Installatie

  1. Installeer de vereisten:

    pip install fastapi uvicorn
  2. Voeg de audit logging middleware toe aan jouw applicatie


πŸš€ Gebruik

1️⃣ Middleware activeren

Voeg de middleware toe aan je FastAPI-applicatie:

from fastapi import FastAPI
from middleware import AuditLogMiddleware

app = FastAPI()
app.add_middleware(AuditLogMiddleware)

2️⃣ Audit event loggen

Je kunt een specifiek audit event loggen met de log_audit_event functie:

from auditlog import log_audit_event

log_audit_event("gebruiker123", "login_poging", "Gebruiker heeft geprobeerd in te loggen")

3️⃣ API Requests en logs

Voorbeeldverzoek:

curl -X GET "http://localhost:8000/" -H "X-Correlation-ID: abc-123"

Response Headers:

X-Request-ID: d39b55f2-4c11-4a60-8e51-bb2e2c6e0d19
X-Correlation-ID: abc-123
X-Server-Hostname: mijnserver
X-App-Version: 1.0.0

Log Output:

INFO: Request: GET http://localhost:8000/ | Request ID: d39b55f2-4c11-4a60-8e51-bb2e2c6e0d19 | Correlation ID: abc-123
INFO: Audit Event | Gebruiker: anoniem | Actie: toegang_home | Details: Gebruiker heeft de startpagina bezocht
INFO: Response: 200 | Request ID: d39b55f2-4c11-4a60-8e51-bb2e2c6e0d19 | Correlation ID: abc-123 | Duration: 0.02s

🎯 Samenvatting

  • βœ… Registreert alle aanvragen en reacties voor traceabilty
  • βœ… Unieke request en correlation ID's om requests aan elkaar tre kunnen correleren
  • βœ… Applicatieversie en hostname toegevoegd aan response headers voor monitoring/audit
  • βœ… Aanpasbare audit event logging d.m.v. een helper
  • βœ… Eenvoudig te integreren als module

About

Common audit logging library for FastAPI applications. Provides standardized audit trail functionality, activity tracking, and compliance logging for API security and governance requirements.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages