fabric icon indicating copy to clipboard operation
fabric copied to clipboard

[Feature request]: Implement global debug output, and --debug=0|1|2|3

Open mattjoyce opened this issue 2 months ago • 1 comments

What do you need?

Implement Global Debug Option

Current State

  • Debug output is inconsistent across packages
  • Some packages use hardcoded debug=false flags
  • Various packages implement their own debuglog() functions
  • Operational info goes to stdout

Proposed Solution

Add global debug level control via --debug flag in common.go

Implementation Details

  1. In common.go:
var (
    DebugLevel int  // 0-3, default 0
)

func init() {
    flag.IntVar(&DebugLevel, "debug", 0, "Debug level (0-3)")
}
  1. Create common debug function:
func DebugLog(level int, format string, args ...interface{}) {
    if level <= DebugLevel {
        fmt.Printf(format+"\n", args...)
    }
}
  1. Usage across packages:
common.DebugLog(1, "basic debug info: %v", someVar)
common.DebugLog(2, "more detailed: %v", details)
common.DebugLog(3, "trace level: %v", everything)

Migration Plan

  1. Replace existing debug=false constants with global level check
  2. Convert existing debuglog() functions to use common.DebugLog()
  3. Document debug levels in code and README:
    • 0: off (default)
    • 1: basic debug info
    • 2: detailed debugging
    • 3: trace level

Benefits

  • Consistent debug control across codebase
  • Runtime control via CLI flag
  • No additional dependencies
  • Minimal changes to existing code structure

Once this is done, revisit with increased debugging in other packages.

mattjoyce avatar Dec 22 '24 06:12 mattjoyce