An Ode to Logging

Mon, Sep 2, 2024 One-minute read
Oh, log, a nerdy scribe,
In you, all errors hide.
To write it well - not an easy quest,
Let's see how we can do it best!

True hackers always start with print()
Don't judge! They've got no time this sprint.
But push to prod - a fatal flaw.
Use proper logger - that's the law!

Distinguish noise from fatal crash -
Use Info, Error, Warn, and Trace.
Put a clear level in each line,
To sift through data, neat design!

You log for humans, this is true...
But can a machine read it too?
Structure is key, JSON, timestamp...
Grafana tells you: "You're the champ!"

Events, like books, have start and end.
Use Spans to group them all, my friend.
Then take these Spans and build a tree,
We call it Trace, it's cool agree?

Redact your logs: remove emails,
addresses, PII details.
Or data breach is soon to come,
and trust me, it's not fun :(

In modern distributed world,
Do centralize your logs, my Lord.
Retention policy in place?
Or cloud bill you will embrace!

(No LLMs have been used to write this)