Documentation ¶
Overview ¶
Package llog is a dirt-simple leveled text logger.
Example ¶
package main import ( "flag" "log/slog" "github.com/u-root/uio/llog" ) func someFunc(v llog.Printf) { v("logs at the given level %s", "foo") } func main() { l := llog.Default() // If -v is set, l.Level becomes slog.LevelDebug. l.RegisterDebugFlag(flag.CommandLine, "v") flag.Parse() someFunc(l.Debugf) someFunc(l.AtLevelFunc(slog.LevelWarn)) someFunc(l.Infof) }
Output:
Index ¶
- type Logger
- func (l *Logger) AtLevel(level slog.Level) Printfer
- func (l *Logger) AtLevelFunc(level slog.Level) Printf
- func (l *Logger) Debugf(fmt string, args ...any)
- func (l *Logger) Errorf(fmt string, args ...any)
- func (l *Logger) Infof(fmt string, args ...any)
- func (l *Logger) Logf(level slog.Level, fmt string, args ...any)
- func (l *Logger) RegisterDebugFlag(f *flag.FlagSet, flagName string)
- func (l *Logger) RegisterLevelFlag(f *flag.FlagSet, flagName string)
- func (l *Logger) RegisterVerboseFlag(f *flag.FlagSet, flagName string, verboseLevel slog.Level)
- func (l *Logger) Warnf(fmt string, args ...any)
- type Printf
- type Printfer
- type Sink
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
Logger is a dirt-simple leveled logger.
If the log level is >= Level, it logs to the given Sink.
Logger or Sink may be nil in order to log nothing.
func Default ¶
func Default() *Logger
Default is the stdlib default log sink.
Example (Withtime) ¶
package main import ( "log/slog" "github.com/u-root/uio/llog" ) func main() { l := llog.Default() l.Infof("An INFO level string") l.Debugf("A DEBUG level that does not appear") l.Level = slog.LevelDebug l.Debugf("A DEBUG level that appears") }
Output:
func New ¶
New creates a logger from p which prepends the log level to the output and uses l as the default log level.
Logs with level >= l will be printed using p.
func (*Logger) AtLevel ¶
AtLevel returns a Printfer that can be passed around to log at the given level.
AtLevel never returns nil.
func (*Logger) AtLevelFunc ¶
AtLevelFunc returns a Printf that can be passed around to log at the given level.
AtLevelFunc never returns nil.
func (*Logger) RegisterDebugFlag ¶
RegisterDebugFlag registers a boolean flag that, if set, assigns LevelDebug as the level.
func (*Logger) RegisterLevelFlag ¶
RegisterLevelFlag registers a flag that sets the given numeric level as the level.
func (*Logger) RegisterVerboseFlag ¶
RegisterVerboseFlag registers a boolean flag that, if set, assigns verboseLevel as the level.
type Printf ¶
Printf is a logger printf function.
func MultiPrintf ¶
MultiPrintf is a Printf that prints to all given p.
func WritePrintf ¶
WritePrintf is a Printf that prints lines to w.