Files
seaweedfs/seaweed-block/internal/logging/logging.go
T

35 lines
822 B
Go

// Package logging configures process logs. Standard log calls remain INFO;
// Debugf adds diagnostics only when the process explicitly selects debug.
package logging
import (
"fmt"
"log"
"sync/atomic"
)
var debugEnabled atomic.Bool
func ValidateLevel(level string) error {
if level != "info" && level != "debug" {
return fmt.Errorf("--log-level must be info or debug (got %q)", level)
}
return nil
}
// Configure validates before changing anything. Call once at process startup.
func Configure(level string) error {
if err := ValidateLevel(level); err != nil {
return err
}
log.SetFlags(log.LstdFlags | log.Lmicroseconds | log.LUTC)
debugEnabled.Store(level == "debug")
return nil
}
func Debugf(format string, args ...any) {
if debugEnabled.Load() {
log.Printf("level=DEBUG "+format, args...)
}
}