Centralize BD_DEBUG logging into internal/debug package

- Created internal/debug package with Enabled(), Logf(), Printf()
- Added comprehensive unit tests for debug package
- Replaced 50+ scattered os.Getenv("BD_DEBUG") checks across 9 files
- Centralized debug logic for easier maintenance and testing
- All tests passing, behavior unchanged

Closes bd-fb95094c.5
This commit is contained in:
Steve Yegge
2025-11-06 20:14:22 -08:00
parent 04621fe731
commit 95cbcf4fbc
16 changed files with 364 additions and 280 deletions

View File

@@ -8,6 +8,7 @@ import (
"time"
"github.com/spf13/viper"
"github.com/steveyegge/beads/internal/debug"
)
var v *viper.Viper
@@ -103,14 +104,10 @@ func Initialize() error {
if err := v.ReadInConfig(); err != nil {
return fmt.Errorf("error reading config file: %w", err)
}
if os.Getenv("BD_DEBUG") != "" {
fmt.Fprintf(os.Stderr, "Debug: loaded config from %s\n", v.ConfigFileUsed())
}
debug.Logf("Debug: loaded config from %s\n", v.ConfigFileUsed())
} else {
// No config.yaml found - use defaults and environment variables
if os.Getenv("BD_DEBUG") != "" {
fmt.Fprintf(os.Stderr, "Debug: no config.yaml found; using defaults and environment variables\n")
}
debug.Logf("Debug: no config.yaml found; using defaults and environment variables\n")
}
return nil