Documentation ¶
Overview ¶
Example ¶
package main import ( "github.com/mpuzanov/wslog" ) func main() { wslog.RemoveTime = true l := wslog.NewEnv("local") l.Info("hello") }
Output: level=INFO msg=hello
Index ¶
- Variables
- func AppendCtx(parent context.Context, attr slog.Attr) context.Context
- func ContextWithLogger(ctx context.Context, l *slog.Logger) context.Context
- func GetLogLevel() slog.Level
- func SetLogLevel(level string) slog.Level
- type Attr
- type ContextHandler
- type Handler
- type HandlerOptions
- type Level
- type LogValuer
- type Logger
- type LoggerOption
- type Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // SetDefault ... SetDefault = slog.SetDefault // String алиасы типов String = slog.String // Bool ... Bool = slog.Bool // Float64 ... Float64 = slog.Float64 // Any ... Any = slog.Any // Duration ... Duration = slog.Duration // Int ... Int = slog.Int // Int64 ... Int64 = slog.Int64 // GroupValue ... GroupValue = slog.GroupValue // Group ... Group = slog.Group )
View Source
var ( // RemoveTime убрать time из логов RemoveTime bool )
Functions ¶
func AppendCtx ¶ added in v0.1.2
AppendCtx adds an slog attribute to the provided context so that it will be included in any Record created with such context
Example ¶
package main import ( "context" "github.com/mpuzanov/wslog" ) func main() { wslog.RemoveTime = true l := wslog.New() ctx := wslog.AppendCtx(context.Background(), wslog.String("userID", "1")) l.InfoContext(ctx, "example1") ctx = wslog.AppendCtx(ctx, wslog.String("userID", "2")) l.InfoContext(ctx, "example2") ctx = wslog.AppendCtx(ctx, wslog.String("metod", "GET")) l.InfoContext(ctx, "example3") }
Output: level=INFO msg=example1 userID=1 level=INFO msg=example2 userID=2 level=INFO msg=example3 userID=2 metod=GET
func ContextWithLogger ¶
ContextWithLogger adds logger to context
Types ¶
type ContextHandler ¶ added in v0.1.2
ContextHandler ...
type Logger ¶
Logger алиасы типов
type LoggerOption ¶
type LoggerOption func(options *options)
LoggerOption ...
func WithAddSource ¶
func WithAddSource(addSource bool) LoggerOption
WithAddSource logger option sets the add source option, which will add source file and line number to the log record.
Click to show internal directories.
Click to hide internal directories.