pegasus/backend/internal/debuglog.go

37 lines
851 B
Go
Raw Normal View History

2025-09-16 00:05:16 -05:00
// backend/internal/debuglog.go
2025-09-08 00:48:47 -05:00
package internal
import (
"log"
"net/http"
"os"
"strings"
)
2026-04-11 00:02:59 -03:00
// Debug enables verbose request and state logging.
2025-09-08 00:48:47 -05:00
var Debug = os.Getenv("PEGASUS_DEBUG") == "1"
2026-04-11 00:02:59 -03:00
// DryRun makes mutating handlers log their intent instead of touching disk.
2025-09-08 00:48:47 -05:00
var DryRun = os.Getenv("PEGASUS_DRY_RUN") == "1"
2026-04-11 00:02:59 -03:00
// Logf writes a log line only when Debug is enabled.
2025-09-08 00:48:47 -05:00
func Logf(format string, args ...any) {
if Debug {
log.Printf(format, args...)
}
2025-09-08 00:48:47 -05:00
}
2026-04-11 00:02:59 -03:00
// RedactHeaders clones a header map and masks sensitive values.
2025-09-08 00:48:47 -05:00
func RedactHeaders(h http.Header) http.Header {
cp := http.Header{}
for k, v := range h {
kk := strings.ToLower(k)
if kk == "cookie" || strings.HasPrefix(kk, "authorization") || strings.Contains(kk, "token") {
cp[k] = []string{"<redacted>"}
} else {
cp[k] = append([]string(nil), v...)
}
}
return cp
}