logger

package
v0.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

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

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 AsciiLogo() string

func Color

func Color(text string, color chalk.Color) string

func ColorEnabled

func ColorEnabled() bool

func Err added in v0.12.0

func Err(e error) slog.Attr

func GinLogger added in v0.5.4

func GinLogger(lg *slog.Logger) gin.HandlerFunc

func New

func New(opts ...LoggerOption) *slog.Logger

func NewLogr added in v0.12.0

func NewLogr(opts ...LoggerOption) logr.Logger

func NewNop added in v0.12.0

func NewNop() *slog.Logger

func NewPluginLogger added in v0.5.4

func NewPluginLogger(opts ...LoggerOption) *slog.Logger

func ParseLevel added in v0.12.0

func ParseLevel(lvl string) slog.Level

func TextStyle

func TextStyle(text string, textStyle chalk.TextStyle) string

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 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

type LoggerOptions

type LoggerOptions struct {
	Level              slog.Level
	AddSource          bool
	ReplaceAttr        func(groups []string, a slog.Attr) slog.Attr
	Writer             io.Writer
	ColorEnabled       bool
	Sampling           *slogsampling.ThresholdSamplingOption
	TimeFormat         string
	TotemFormatEnabled bool
	OmitLoggerName     bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL