CC-201b · Module 2
Debug Log Strategies
3 min read
When something breaks and the error message is not enough, strategic logging is the fastest path to understanding. The pattern with Claude is deliberate: do not add console.log everywhere and hope for the best. Instead, form a hypothesis about where the bug is, tell Claude your hypothesis, and ask it to add targeted log statements at the specific decision points that will confirm or refute your theory. "I think the issue is in the auth middleware — add a log before the token verification step and after it, including the token value and the verification result."
Claude excels at interpreting error output once it has it. Paste an error stack trace directly into the conversation and Claude will trace the call chain, identify the likely failure point, and propose a fix. The same works for log output — paste the log lines and say "here is what the application logged when the bug occurred." Claude maps the log values back to the code paths and identifies where the behavior diverges from the expected flow. The combination of targeted logging and Claude's interpretation creates a debugging loop that is faster than stepping through a debugger in most cases.
- Step 1: Hypothesize Before adding any logs, form a theory about where the bug is. "I think the user object is null after the auth check" is a hypothesis. "Something is broken" is not.
- Step 2: Instrument Tell Claude to add targeted log statements at the specific decision points that will prove or disprove your hypothesis. Include relevant variable values, not just "reached here" markers.
- Step 3: Reproduce Run the failing scenario and collect the log output. Copy the relevant lines.
- Step 4: Interpret Paste the log output into Claude. It will map values back to code paths, identify the divergence from expected behavior, and propose a targeted fix.