restructured logger from budigt

This commit is contained in:
juancwu 2026-04-25 20:35:03 +00:00
commit b2fd12b1c8
11 changed files with 1227 additions and 1 deletions

41
splinter.go Normal file
View file

@ -0,0 +1,41 @@
// Package splinter is a small, opinionated logger that fans out structured
// records to one or more streams (console, file, custom). The default
// package-level logger writes JSON to stderr at LevelInfo; replace it with
// SetDefault to wire in your own configuration.
package splinter
import "sync"
var (
defaultMu sync.RWMutex
def = New(WithStream(NewConsoleStream(ConsoleJSON, LevelInfo)))
)
// Default returns the package-level Logger.
func Default() *Logger {
defaultMu.RLock()
defer defaultMu.RUnlock()
return def
}
// SetDefault replaces the package-level Logger. The previous Logger is
// returned so the caller can Close it if they own its streams.
func SetDefault(l *Logger) *Logger {
defaultMu.Lock()
prev := def
def = l
defaultMu.Unlock()
return prev
}
// Debug logs at LevelDebug on the default Logger.
func Debug(msg string, args ...any) { Default().Debug(msg, args...) }
// Info logs at LevelInfo on the default Logger.
func Info(msg string, args ...any) { Default().Info(msg, args...) }
// Warn logs at LevelWarn on the default Logger.
func Warn(msg string, args ...any) { Default().Warn(msg, args...) }
// Error logs at LevelError on the default Logger.
func Error(msg string, args ...any) { Default().Error(msg, args...) }