Course contentsShow
← Software Engineering
Lesson 1123 of 1,93334. Logging and ObservabilityFree lesson

Writing Effective Log Messages

Crafting clear, actionable log messages with sufficient context for debugging without overwhelming detail.

Writing Effective Log Messages

You'll learn how to craft log messages that speed up debugging without creating noise.

The Goldilocks Problem

Writing log messages is like leaving breadcrumbs for your future self (or teammates) who need to debug a problem at 2 AM. Too few breadcrumbs? You're lost. Too many? You can't see the path through the clutter. The art is finding the "just right" balance.

What Makes a Log Message Effective?

An effective log message answers three questions instantly:

  1. What happened? State the event clearly
  2. Where did it happen? Provide context (component, user, transaction)
  3. Why does it matter? Include relevant data to make decisions

Clarity First

Bad: "Error in process" Good: "Failed to process payment: transaction timeout after 30s"

The good message tells you what failed, which operation, and why it failed—all without requiring you to dig through code.

Context is King

Include identifiers that let you trace the request or user journey:

  • Transaction/request IDs
  • User identifiers (anonymized if needed)
  • Resource names or IDs
  • Relevant input values

Bad: "User authentication failed" Good: "User authentication failed for user_id=12345 from IP=192.168.1.100: invalid password"

Actionable, Not Overwhelming

Don't log every variable. Log what helps diagnosis. If a database query fails, log the query type and key parameters—not the entire 500-line SQL dump.

Think: "If I saw this log at 2 AM, what would help me fix it quickly?"

Key Takeaway: Effective log messages are clear, contextual, and actionable—they tell you exactly what happened, where, and provide just enough data to diagnose the issue without drowning you in details.