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.<p>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.<p>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:<p>* New message from me@example.com to you@other.com<p>* Subject "test 123"<p>* Generating message using template xyz<p>* Checking sender against block lists<p>* Sender block list check passed<p>* Connecting to SMTP server smtp1.example.com..<p>* SMTP authentication succeeded, server responded "235 2.7.0 Authentication successful"<p>* Send succeeded: "250 ok"<p>This is ok when you're writing the code initially, but much better is a single line (or single structured message):<p>* 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"<p>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.