41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
// 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...) }
|