Skip to main content

πŸ“Š Global Audit Logging System

XR-MDT includes a robust, centralized logging system designed to track every critical action performed within the tablet. This ensures accountability and provides a clear audit trail for server administrators.

πŸ” How it Works

The logging system operates on a dual-path architecture:
  1. Database Persistence: Every log is stored in the mdt_logs table for long-term historical review.
  2. Real-time Webhooks: Logs are immediately forwarded to configured Discord channels based on the action type and faction, separated into administrative and operational webhooks.
The AddLog function is implemented in server/sv_logs.lua and is exposed as a server-side export.

πŸ› οΈ Usage for Developers

Trigger logs from any server-side script using the AddLog export.

Export Signature

What Gets Logged Automatically

The AddLog function automatically resolves and stores:
  • citizenid β€” from Bridge.GetCitizenIdFromObject(player).
  • name β€” "firstname lastname" from Bridge.GetCharInfo(player).
  • rank β€” player’s current job grade name.

Database Schema (mdt_logs)

Examples


βš™οΈ Configuration

Webhooks are configured in configs/config.webhook.lua.

Webhook Routing Priority

The system routes logs based on the action type and its destination mapping:
  1. Routing Mapping: The action type is resolved against Config.Webhooks.Routing. It returns:
    • "admin" β€” Administrative events (hiring, firing, code changes, deletions).
    • "faction" β€” Operational/faction events (fines, reports, armory).
    • "both" β€” Dispatched to both administrative and operational channels.
    • If not zmapowany, default is "faction" (defined as ["Default"] = "faction").
  2. Override Checks (debugType): Checks if a specific override webhook exists under Config.Webhooks.Types[debugType]. If set, it will override the faction webhook.
  3. Specific Faction Webhooks:
    • Operational logs: routes to Config.Webhooks.Jobs[JOB_UPPERCASE].Faction, then falls back to Config.Webhooks.FactionMain.
    • Administrative logs: routes to Config.Webhooks.Jobs[JOB_UPPERCASE].Admin, then falls back to Config.Webhooks.AdminMain.
  4. Main Webhook: Final fallback to Config.Webhooks.Main if any of the above paths are empty or not configured.

Example Webhook Configuration Structure


πŸ–₯️ NUI Log Viewer

Authorized employees can view logs directly within the MDT:
  • Navigate to the Logs tab in any tablet.
  • Logs are fetched via a server callback returning the last 200 entries for the job.
  • Search by name, action type, or details.
  • Filter results in real-time.
[!NOTE] By default, the Logs tab is visible to higher ranks. Permissions are controlled via logs_view = true in the respective Grades tables.

Β© XR-Core Systems | Professional FiveM Resources