Application-Level Logging Best Practices
Something I wish this discussed more was development vs production logs. It talks about a unique request identifier across microservices, but this applies within a single service too.In your development environment, you're usually only doing one request/job at a time, and so logging each step along the way makes it easy to follow and debug. In production, with tens or even thousands of concurrent requests, this quicky becomes basically impossible.I've become a huge fan of fewer but "wider" lines. Take sending an email.. I'm sure most people have seen (or even written) logs like:* New message from me@example.com to you@other.com* Subject "test 123"* Generating message using template xyz* Checking sender against block lists* Sender block list check passed* Connecting to SMTP server smtp1.example.com..* SMTP authentication succeeded, server responded "235 2.7.0 Authentication successful"* Send succeeded: "250 ok"This is ok when you're writing the code initially, but much better is a single line (or single structured message):* Outgoing mail message. from="me@example.com" to="you@example.com" Subject="test 123" blocklist=passed template=xyz smtp_server=smtp1.example.com smtp_auth="235 2.7.0 Authentication successful" smtp_Status="250 ok"All the context needed (whether succeeded or not), compact, and concurrent requests are a non-issue. I can't say I'm fully on the "structured log" bandwagon just yet (mostly because I haven't found a tool I like enough to give up the simplicity of a text editor), but I can see the appeal for sure.