Documentation
¶
Overview ¶
Package tint provides a slog.Handler that writes tinted logs. The output format is inspired by the zerolog.ConsoleWriter.
Example ¶
package main
import (
"errors"
"os"
"time"
"github.com/lmittmann/tint"
"golang.org/x/exp/slog"
)
func main() {
slog.SetDefault(slog.New(tint.Options{
Level: slog.LevelDebug,
TimeFormat: time.Kitchen,
}.NewHandler(os.Stderr)))
slog.Info("Starting server", "addr", ":8080", "env", "production")
slog.Debug("Connected to DB", "db", "myapp", "host", "localhost:5432")
slog.Warn("Slow request", "method", "GET", "path", "/users", "duration", 497*time.Millisecond)
slog.Error("DB connection lost", tint.Err(errors.New("connection reset")), "db", "myapp")
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHandler ¶
NewHandler creates a slog.Handler that writes tinted logs to Writer w, using the default options.
Types ¶
type Options ¶
type Options struct {
// Minimum level to log (Default: slog.LevelInfo)
Level slog.Level
// Time format (Default: time.StampMilli)
TimeFormat string
// Disable color (Default: false)
NoColor bool
}
Options for a slog.Handler that writes tinted logs. A zero Options consists entirely of default values.
func (Options) NewHandler ¶
NewHandler creates a slog.Handler that writes tinted logs to Writer w with the given options.
Click to show internal directories.
Click to hide internal directories.