Chapter 95: Logging with Loki, Elastic Stack and CloudWatch
95.2 One event — timestamp, severity and structured JSON
Story (fictional teaching scenario). At a fictional Nashik shop, Meera and Sara from Oslo replace a vague “something broke” message with a few consistent fields.
Why
Stable fields let computers filter without guessing the meaning of free-form sentences.
What
- An event is one occurrence being recorded.
- A timestamp says when it happened; include an offset or UTC marker.
- Severity classifies importance. INFO, WARN and ERROR here are application conventions, not identical rules across all products.
- Structured logging stores named fields instead of only a sentence.
- A schema describes allowed field names and types.
How
-
Choose a small stable schema.
-
Keep duration fields numeric and state their unit.
-
Use one JSON object per line for this lab.
-
Do not put a request body or credential in the message.
Example 1: A harmless event
- Read the command or request.
{"ts":"2026-11-01T00:00:03Z","service":"bakery-api","level":"ERROR","request_id":"req-demo-003","status":500,"latency_ms":800}
- Read the result.
Output (illustrative; NOT executed against Loki, Elastic or CloudWatch)
One event: status 500, duration 800 milliseconds, fictional request req-demo-003.
- Line by line:
tsuses Z for UTC.serviceidentifies the producer.levelis our chosen severity.request_idis an invented correlation value.statusis an integer HTTP result code.latency_msis an integer duration in milliseconds. JSON quotes strings, not these numbers.
Ravindra Bagale's Tip
Keep the field type and time unit consistent.
Field type आणि time unit एकसारखे ठेवा.
Field type और time unit एक जैसे रखो.
Did you understand? Let us try it once more.