Chapter 95: Logging with Loki, Elastic Stack and CloudWatch
95.13 Time zones, parsing and multiline stack traces
Story (fictional teaching scenario). At a fictional Pune support desk, Sara from Oslo sees 00:00 UTC while Priya sees 05:30 IST. They realize it is the same instant, not two outages.
Why
Incorrect time interpretation and broken multiline grouping can hide the event you need.
What
- UTC is a common reference time; IST here is Asia/Calcutta at UTC+05:30.
- An offset-aware timestamp states its relationship to UTC.
- Parsing converts text into structured values; a malformed record must be accounted for.
- A multiline event spans physical lines, such as a stack trace. A framing rule decides which lines belong together.
How
-
Store explicit offsets or UTC and choose display time intentionally.
-
Reject or quarantine malformed synthetic records without hiding a rejected count.
-
Join stack lines near the producer with format-specific rules.
-
Keep one JSON object per line by encoding embedded newlines inside a string.
Example 1: Convert one instant locally
- Read the command or request.
from datetime import datetime, timezone, timedelta
dt = datetime.fromisoformat("2026-11-01T00:00:00+00:00")
print(dt.astimezone(timezone(timedelta(hours=5, minutes=30))).isoformat())
- Read the result.
Output (ACTUAL deterministic local Python; NOT a logging-stack integration)
2026-11-01T05:30:00+05:30
- Line by line: The import supplies time handling.
fromisoformatreads an explicit UTC offset.astimezoneconverts the instant to IST without adding a second false offset. This same transform is actually tested in the local lab, including date rollover.
Example 2: Frame a fake stack
- Read the command or request.
ERROR fictional_failure
at demo.py:1
ERROR next_failure
- Read the result.
Output (illustrative; NOT executed against Loki, Elastic or CloudWatch)
Event 1: ERROR fictional_failure plus its indented continuation.
Event 2: ERROR next_failure.
- Line by line: This is an artificial start-line rule, not a general stack parser. Wrong framing can merge unrelated requests or split one failure into many alerts. No real exception log is read.
Ravindra Bagale's Tip
Changing display time is not changing when the event happened.
Display time बदलला तरी event घडलेली वेळ बदलत नाही.
Display time बदलने से event का असली समय नहीं बदलता.
Did you understand? Let us try it once more.