Below is a human‑friendly view of structured logs capturing request/response flows with timestamp
, trn_id
, function
, direction
, endpoint
, status
, duration_ms
, and payload
. Try filtering.
Timestamp | TRN‑ID | Function | Direction | Endpoint | Status | Duration (ms) | Payload |
---|
Standard JSON Log Record
{
"timestamp": "2025-09-08T10:12:33.187Z",
"trn_id": "TRN-20250908-00123",
"function": "createPayment",
"direction": "REQUEST",
"endpoint": "POST /pg/payments",
"status": null,
"duration_ms": null,
"data": {
"amount": 12000,
"currency": "MYR",
"channel": "FPX",
"customer_id": "CUST-99",
"meta": {"order_ref": "ORD-55231"}
}
}
Raw Linux Tail — Ideal Log Format
Below is a sample tail -f app.log
style output showing structured log entries in JSON per line.
2025-09-08T09:59:12.101Z INFO TRN-20250908-00001 createPayment REQUEST - {"amount":2500,"currency":"MYR","channel":"FPX","order_ref":"ORD-10001"} TRN-20250908-00123 createPayment REQUEST - {"amount":12000,"currency":"MYR","channel":"FPX","order_ref":"ORD-55231"}
2025-09-08T10:12:33.499Z INFO TRN-20250908-00123 createPayment RESPONSE - {"pg_ref":"PG-77777","status":"PENDING"}
2025-09-08T10:13:04.105Z INFO TRN-20250908-00123 paymentStatus REQUEST - {}
2025-09-08T10:13:04.220Z INFO TRN-20250908-00123 paymentStatus RESPONSE - {"status":"SUCCESS","channel":"FPX"}
2025-09-08T10:15:12.009Z WARN TRN-20250908-00124 refund REQUEST - {"pg_ref":"PG-77777","amount":12000,"reason":"Customer request"}
2025-09-08T10:15:12.380Z INFO TRN-20250908-00124 refund RESPONSE - {"refund_ref":"RF-55231","status":"QUEUED"}
2025-09-08T10:17:55.532Z ERROR TRN-20250908-00125 webhookPayment WEBHOOK - {"pg_ref":"PG-88888","status":"FAILED","reason":"DECLINED"}
Best Practices for Log Rotation
- Use
logrotate
on Linux to automatically rotate, compress, and purge old logs. - Rotate daily or when file size exceeds a threshold (e.g., 100 MB) to avoid huge files.
- Keep 7–14 days of detailed logs locally, archive older logs to S3 or centralized storage.
- Always include
timestamp
,TRN-ID
, andrequest/response
markers in each entry for traceability. - Test recovery: ensure rotated/compressed logs can still be read for audits.