mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-01-08 22:08:03 -05:00
- Part 1 of incorporating `modernize` tool into Fabric.
- Replace `interface{}` with `any` in slice type declarations
- Update map types from `map[string]interface{}` to `map[string]any`
- Change variadic function parameters to use `...any` instead of `...interface{}`
- Modernize JSON unmarshaling variables to `any` for consistency
- Update struct fields and method signatures to prefer `any` alias
- Ensure all type assertions and conversions use `any` throughout codebase
- Add PR guidelines in docs to encourage focused, reviewable changes
79 lines
1.3 KiB
Go
79 lines
1.3 KiB
Go
package log
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"sync"
|
|
)
|
|
|
|
// Level represents the debug verbosity.
|
|
type Level int
|
|
|
|
const (
|
|
// Off disables all debug output.
|
|
Off Level = iota
|
|
// Basic provides minimal debugging information.
|
|
Basic
|
|
// Detailed provides more verbose debugging.
|
|
Detailed
|
|
// Trace is the most verbose level.
|
|
Trace
|
|
)
|
|
|
|
var (
|
|
mu sync.RWMutex
|
|
level Level = Off
|
|
output io.Writer = os.Stderr
|
|
)
|
|
|
|
// SetLevel sets the global debug level.
|
|
func SetLevel(l Level) {
|
|
mu.Lock()
|
|
level = l
|
|
mu.Unlock()
|
|
}
|
|
|
|
// LevelFromInt converts an int to a Level.
|
|
func LevelFromInt(i int) Level {
|
|
switch {
|
|
case i <= 0:
|
|
return Off
|
|
case i == 1:
|
|
return Basic
|
|
case i == 2:
|
|
return Detailed
|
|
case i >= 3:
|
|
return Trace
|
|
default:
|
|
return Off
|
|
}
|
|
}
|
|
|
|
// Debug writes a debug message if the global level permits.
|
|
func Debug(l Level, format string, a ...any) {
|
|
mu.RLock()
|
|
current := level
|
|
w := output
|
|
mu.RUnlock()
|
|
if current >= l {
|
|
fmt.Fprintf(w, "DEBUG: "+format, a...)
|
|
}
|
|
}
|
|
|
|
// Log writes a message unconditionally to stderr.
|
|
// This is for important messages that should always be shown regardless of debug level.
|
|
func Log(format string, a ...any) {
|
|
mu.RLock()
|
|
w := output
|
|
mu.RUnlock()
|
|
fmt.Fprintf(w, format, a...)
|
|
}
|
|
|
|
// SetOutput allows overriding the output destination for debug logs.
|
|
func SetOutput(w io.Writer) {
|
|
mu.Lock()
|
|
output = w
|
|
mu.Unlock()
|
|
}
|