Logging & Auditing
We use a dual-layer logging strategy: Application Logs (for Developers) and Audit Logs (for Admins).
Application Logs (Pino)
Standard output (stdout) in JSON format.
- Level: Configurable via
LOG_LEVEL(info in prod, debug in dev). - Format: JSON (processed by FluentBit/Promtail in production).
- Request ID: Every log line includes
request_idfor tracing.
import logger from "@adonisjs/core/services/logger";
logger.info({ userId: user.id }, "User logged in");
Audit Logs (Database)
Critical actions (Create/Update/Delete) are persisted to the logs table via LogsService.
This allows Admins to see "Who did what?" in the dashboard.
Tracked Events:
CAMERA_CREATE,CAMERA_DELETEUSER_INVITESETTINGS_UPDATE
await LogsService.create({
action: "CAMERA_UPDATE",
userId: auth.user.id,
targetId: camera.id,
metadata: { oldName: "Foo", newName: "Bar" },
});