logger

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError
	LevelDebug = slog.LevelDebug
)

Variables

View Source
var (
	NewTextHandler = slog.NewTextHandler
	NewJSONHandler = slog.NewJSONHandler
	New            = slog.New
	SetDefault     = slog.SetDefault

	StringAttr   = slog.String
	BoolAttr     = slog.Bool
	Float64Attr  = slog.Float64
	AnyAttr      = slog.Any
	DurationAttr = slog.Duration
	IntAttr      = slog.Int
	Int64Attr    = slog.Int64
	Uint64Attr   = slog.Uint64

	GroupValue = slog.GroupValue
	Group      = slog.Group
)

Functions

func ContextWithLogger

func ContextWithLogger(ctx context.Context, l *slog.Logger) context.Context

ContextWithLogger adds logger to context.

Types

type Attr

type Attr = slog.Attr

func ErrAttr

func ErrAttr(err error) Attr

func Float32Attr

func Float32Attr(key string, val float32) Attr

func Int32Attr

func Int32Attr(key string, val int32) Attr

func TimeAttr

func TimeAttr(key string, time time.Time) Attr

func UInt32Attr

func UInt32Attr(key string, val uint32) Attr

type Handler

type Handler = slog.Handler

type HandlerOptions

type HandlerOptions = slog.HandlerOptions

type Level

type Level = slog.Level

type LogValuer

type LogValuer = slog.LogValuer

type Logger

type Logger = slog.Logger

func Default

func Default() *Logger

func L

func L(ctx context.Context) *Logger

func NewLogger

func NewLogger(opts ...Option) *Logger

func WithAttrs

func WithAttrs(ctx context.Context, attrs ...Attr) *Logger

WithAttrs returns logger with attributes.

func WithDefaultAttrs

func WithDefaultAttrs(logger *Logger, attrs ...Attr) *Logger

WithDefaultAttrs returns logger with default attributes.

type Option

type Option func(*Options)

func WithAddSource

func WithAddSource(addSource bool) Option

WithAddSource logger option sets the add source option, which will add source file and line number to the log record.

func WithIsJSON

func WithIsJSON(isJSON bool) Option

WithIsJSON logger option sets the is json option, which will set JSON format for the log record.

func WithLevel

func WithLevel(level string) Option

WithLevel logger option sets the log level, if not set, the default level is Info.

func WithSetDefault

func WithSetDefault(setDefault bool) Option

WithSetDefault logger option sets the set default option, which will set the created logger as default logger.

type Options

type Options struct {
	Level      Level
	AddSource  bool
	IsJSON     bool
	SetDefault bool
}

type Value

type Value = slog.Value

Jump to

Keyboard shortcuts

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