Skip to content

Instantly share code, notes, and snippets.

@DanielCardonaRojas
Created October 21, 2025 17:03
Show Gist options
  • Save DanielCardonaRojas/6f61c542a619fb82056d703a94f25f98 to your computer and use it in GitHub Desktop.
Save DanielCardonaRojas/6f61c542a619fb82056d703a94f25f98 to your computer and use it in GitHub Desktop.
Add logs that help spot the issue
description argument-hint
Insert strategic logs to spot the issue
PREFIX

Automatically insert strategic debug logs into the code based on the current context. Logs follow a hierarchical taxonomy for easy filtering.

Usage

/debugLogs {PREFIX}

  • PREFIX (optional): Custom prefix for all log statements. Default: >>>

Examples:

  • /debug-logs - Uses default >>> prefix
  • /debug-logs DEBUG - Uses DEBUG prefix
  • /debug-logs [MyApp] - Uses [MyApp] prefix

Logging Guidelines

Insert debug logs that:

  1. Use hierarchical prefixes for filtering:

    • Base prefix: {PREFIX}
    • Module/file level: {PREFIX} [ModuleName]
    • Class level: {PREFIX} [ModuleName:ClassName]
    • Method level: {PREFIX} [ModuleName:ClassName.methodName]
    • Sub-operation level: {PREFIX} [ModuleName:ClassName.methodName:operation]
  2. Follow these principles:

    • Place logs at critical decision points, state changes, and error boundaries
    • Include relevant variable values and state information
    • Log entry/exit points of important functions with parameters/return values
    • Add logs before/after external calls (API, database, file system)
    • Capture conditional branch decisions
    • Log loop iterations for complex loops (with iteration count)
  3. Use consistent formatting:

    • Entry: {PREFIX} [Scope] → methodName(param1=value1, param2=value2)
    • Exit: {PREFIX} [Scope] ← methodName returned: value
    • State: {PREFIX} [Scope] state: variableName=value
    • Decision: {PREFIX} [Scope] condition: expression=true/false, taking branch X
    • Error: {PREFIX} [Scope] ⚠ error: description
    • Event: {PREFIX} [Scope] event: description
  4. Use language-appropriate print statements:

    • Python: print("{PREFIX} [Scope] message")
    • JavaScript/TypeScript: console.log("{PREFIX} [Scope] message")
    • Java: System.out.println("{PREFIX} [Scope] message")
    • C/C++: printf("{PREFIX} [Scope] message\n")
    • Go: fmt.Println("{PREFIX} [Scope] message")
    • Rust: println!("{PREFIX} [Scope] message")
    • Ruby: puts "{PREFIX} [Scope] message"
    • PHP: echo "{PREFIX} [Scope] message\n"
    • Swift: print("{PREFIX} [Scope] message")

Your Task

  1. Check if a custom prefix was provided: Look for a prefix argument in the slash command invocation (e.g., /debug-logs DEBUG). If provided, use that prefix instead of {PREFIX} for all log statements.
  2. Analyze the current conversation context to identify the code being debugged
  3. Read the relevant source files
  4. Determine the appropriate scope hierarchy (module, class, method names)
  5. Automatically insert print statements at critical code locations using the Edit tool, using the custom prefix if provided
  6. Focus on these critical areas:
    • Function entry/exit points with parameters and return values
    • State transitions and variable mutations
    • Conditional branches and loop iterations
    • Error handling paths
    • Async operations and callbacks
    • External calls (API, database, file system)
  7. After inserting logs, provide:
    • Summary of files modified and number of logs added
    • Filtering commands the user can use to view specific log groups (using the actual prefix that was used):
      • Filter by module: grep "{PREFIX} \[ModuleName"
      • Filter by class: grep "{PREFIX} \[ModuleName:ClassName"
      • Filter by method: grep "{PREFIX} \[ModuleName:ClassName.methodName"

IMPORTANT: Use the Edit tool to insert the actual print/console.log statements directly into the code files. Do not just show what the logs would look like - actually modify the files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment