2.8 KiB
Logging & debugging errors
Where errors are logged
1. Log file (JSON lines)
- Path:
LOG_FILEenv var, or/tmp/mis-control-tower.logif unset. - Contents: JSON lines for
requireSession.error,getOverviewData.error,OverviewPage.getOverviewData.error, plus anylogLine(...)usage (e.g. health, signup).
View recent entries:
tail -f /tmp/mis-control-tower.log
Or with a custom path:
export LOG_FILE=/var/log/mis-control-tower.log
# then start the app; tail that path
tail -f /var/log/mis-control-tower.log
2. Process stdout / stderr
console.errorandconsole.loggo to the process that runs Next.js.- Dev: terminal where you run
npm run dev. - Production: PM2 logs (
pm2 logs), Docker (docker logs ...), systemd (journalctl -u your-service -f), etc.
3. Debug logs API (optional)
- URL:
GET /api/debug/logs?key=YOUR_DEBUG_LOGS_KEY - Purpose: Returns the last 100 lines of the log file as JSON.
- Setup: Add to
.env:DEBUG_LOGS_KEY=your-secret-string - Usage:
curl "https://mis.maliountech.com.mx/api/debug/logs?key=your-secret-string" - If
DEBUG_LOGS_KEYis unset or thekeyparam is wrong, the route returns 401.
Error events we log
| Event | When |
|---|---|
requireSession.error |
Session lookup (cookies / DB) fails |
getOverviewData.error |
Overview data fetch (DB) fails |
OverviewPage.getOverviewData.error |
Overview page catch-around fetch fails |
Each includes message and stack when available.
Quick checks when you see "Internal Server Error"
-
Tail the log file:
tail -f /tmp/mis-control-tower.log
(or$LOG_FILEif you set it.) -
Check process logs:
Wherevernext startornpm run devruns (PM2, Docker, systemd). Look for[requireSession],[getOverviewData],[OverviewPage], or[middleware]. -
Call the debug API (if configured):
curl "https://your-domain/api/debug/logs?key=YOUR_DEBUG_LOGS_KEY"
and inspect theentriesarray for recent errors.
KPI quality trace (Node-RED vs processing)
Use this when Quality is shown as 0 and you need to see exactly what was received and saved.
-
Enable trace logging:
TRACE_KPI_INGEST=1 -
Send KPI payloads as usual from Node-RED.
-
Inspect logs:
tail -f /tmp/mis-control-tower.logor:curl "https://your-domain/api/debug/logs?key=YOUR_DEBUG_LOGS_KEY" -
Look for event
ingest.kpi.trace, which includes:trace.rawQualityCandidates(raw payload values found at multiple paths),trace.normalizedQuality(post-normalization),trace.persistedQuality(value written to DB).
Optional one-shot trace without env var:
- Send header
x-debug-ingest: 1on a KPI request. - The response will include a
traceobject with the same quality details.