Documentation
¶
Overview ¶
Example ¶
slog.SetDefault(slog.New(newColorHandler(os.Stderr, &LoggerOptions{
Level: slog.LevelDebug,
ColorEnabled: true,
})))
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", Err(errors.New("connection reset")), "db", "myapp")
Index ¶
- Variables
- func Color(text string, color chalk.Color) string
- func ColorEnabled() bool
- func Err(e error) slog.Attr
- func New(opts ...LoggerOption) *slog.Logger
- func NewNop() *slog.Logger
- func ParseLevel(lvl string) slog.Level
- func TextStyle(text string, textStyle chalk.TextStyle) string
- type LoggerOption
- func WithColor(color bool) LoggerOption
- func WithDisableCaller() LoggerOption
- func WithLogLevel(l slog.Level) LoggerOption
- func WithOmitLoggerName() LoggerOption
- func WithSampling(cfg *slogsampling.ThresholdSamplingOption) LoggerOption
- func WithTimeFormat(format string) LoggerOption
- func WithWriter(w io.Writer) LoggerOption
- type LoggerOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( DefaultLogLevel = slog.LevelDebug DefaultWriter = os.Stdout DefaultAddSource = true NoRepeatInterval = 3600 * time.Hour // arbitrarily long time to denote one-time sampling DefaultTimeFormat = "2006 Jan 02 15:04:05" )
Functions ¶
func ColorEnabled ¶
func ColorEnabled() bool
func New ¶
func New(opts ...LoggerOption) *slog.Logger
func ParseLevel ¶
Types ¶
type LoggerOption ¶
type LoggerOption func(*LoggerOptions)
func WithColor ¶
func WithColor(color bool) LoggerOption
func WithDisableCaller ¶
func WithDisableCaller() LoggerOption
func WithLogLevel ¶
func WithLogLevel(l slog.Level) LoggerOption
func WithOmitLoggerName ¶
func WithOmitLoggerName() LoggerOption
func WithSampling ¶
func WithSampling(cfg *slogsampling.ThresholdSamplingOption) LoggerOption
func WithTimeFormat ¶
func WithTimeFormat(format string) LoggerOption
func WithWriter ¶
func WithWriter(w io.Writer) LoggerOption
Click to show internal directories.
Click to hide internal directories.