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")
Output:
Index ¶
- Variables
- func AsciiLogo() string
- func Color(text string, color chalk.Color) string
- func ColorEnabled() bool
- func Err(e error) slog.Attr
- func GinLogger(lg *slog.Logger) gin.HandlerFunc
- func New(opts ...LoggerOption) *slog.Logger
- func NewLogr(opts ...LoggerOption) logr.Logger
- func NewNop() *slog.Logger
- func NewPluginLogger(opts ...LoggerOption) *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 WithTotemFormat(enable bool) LoggerOption
- func WithWriter(w io.Writer) LoggerOption
- type LoggerOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( DefaultLogLevel = slog.LevelDebug DefaultWriter io.Writer 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 NewLogr ¶ added in v0.12.0
func NewLogr(opts ...LoggerOption) logr.Logger
func NewPluginLogger ¶ added in v0.5.4
func NewPluginLogger(opts ...LoggerOption) *slog.Logger
func ParseLevel ¶ added in v0.12.0
Types ¶
type LoggerOption ¶
type LoggerOption func(*LoggerOptions)
func WithColor ¶
func WithColor(color bool) LoggerOption
func WithDisableCaller ¶ added in v0.6.0
func WithDisableCaller() LoggerOption
func WithLogLevel ¶
func WithLogLevel(l slog.Level) LoggerOption
func WithOmitLoggerName ¶ added in v0.12.0
func WithOmitLoggerName() LoggerOption
func WithSampling ¶
func WithSampling(cfg *slogsampling.ThresholdSamplingOption) LoggerOption
func WithTimeFormat ¶ added in v0.12.0
func WithTimeFormat(format string) LoggerOption
func WithTotemFormat ¶ added in v0.12.0
func WithTotemFormat(enable bool) LoggerOption
func WithWriter ¶
func WithWriter(w io.Writer) LoggerOption
Click to show internal directories.
Click to hide internal directories.