mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
35 lines
822 B
Go
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...)
|
|
}
|
|
}
|