Documentation
¶
Index ¶
- Constants
- func Debug(msg string, args ...any)
- func DebugContext(ctx context.Context, msg string, args ...any)
- func Error(msg string, args ...any)
- func ErrorContext(ctx context.Context, msg string, args ...any)
- func Info(msg string, args ...any)
- func InfoContext(ctx context.Context, msg string, args ...any)
- func Provider(in di.Injector)
- func Warn(msg string, args ...any)
- func WarnContext(ctx context.Context, msg string, args ...any)
- type Console
- type Handler
- type Level
- type Logger
Examples ¶
Constants ¶
View Source
const ( LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarn = slog.LevelWarn LevelError = slog.LevelError )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Console ¶
type Console struct {
Color color.Writer
Writer io.Writer
AddSource bool
// contains filtered or unexported fields
}
Console handler for printing logs to the terminal
Example ¶
package main
import (
"os"
"log/slog"
"github.com/livebud/color"
"github.com/livebud/log"
)
func main() {
log := slog.New(&log.Console{
Color: color.Ignore(),
Writer: os.Stdout,
AddSource: false,
})
log.WithGroup("hello").Debug("world", "args", 10)
log.Info("hello", "planet", "world", "args", 10)
log.Warn("hello", "planet", "world", "args", 10)
log.Error("hello world", slog.String("planet", "world"), "args", 10)
}
Output: debug: world hello.args=10 info: hello planet=world args=10 warn: hello planet=world args=10 error: hello world planet=world args=10
type Level ¶
func ParseLevel ¶
ParseLevel parses a string into a log level
type Logger ¶
func Multi ¶
Example ¶
package main
import (
"log/slog"
"os"
"github.com/livebud/log"
)
func main() {
log := log.Multi(
log.Filter(log.LevelInfo, &log.Console{Writer: os.Stderr}),
slog.NewJSONHandler(os.Stderr, nil),
)
log.WithGroup("hello").Debug("world", "args", 10)
log.Info("hello", "planet", "world", "args", 10)
log.Warn("hello", "planet", "world", "args", 10)
log.Error("hello world", "planet", "world", "args", 10)
}
Click to show internal directories.
Click to hide internal directories.