wslog

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 8 Imported by: 0

README

Wrapper for slog

Added methods

// NewEnv Creating a logger based on Env (local, dev, prod)  
func NewEnv(env string) *Logger

// New create logger  
func New(opts ...LoggerOption) *Logger

Examples

logger := wslog.New(
		wslog.WithLevel(cfg.Log.Level),
		wslog.WithIsJSON(cfg.Log.IsJSON),
		wslog.WithFileLog(cfg.Log.File),
		wslog.WithAddSource(cfg.Log.AddSource),
	)

or

logger := wslog.NewEnv(cfg.Env)
logger.Debug("debug", wslog.AnyAttr("cfg", cfg))

logger.Info(cfg.ServiceName,
		wslog.StrAttr("version", config.Version),
		wslog.StrAttr("time", config.Time),
		wslog.StrAttr("log_level", cfg.Log.Level),
	)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SetDefault ...
	SetDefault = slog.SetDefault
	// StrAttr алиасы типов
	StrAttr = slog.String
	// BoolAttr ...
	BoolAttr = slog.Bool
	// Float64Attr ...
	Float64Attr = slog.Float64
	// AnyAttr ...
	AnyAttr = slog.Any
	// DurationAttr ...
	DurationAttr = slog.Duration
	// IntAttr ...
	IntAttr = slog.Int
	// Int64Attr ...
	Int64Attr = slog.Int64

	// GroupValue ...
	GroupValue = slog.GroupValue
	// Group ...
	Group = slog.Group
)

Functions

func ContextWithLogger

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

ContextWithLogger adds logger to context

func GetLogLevel

func GetLogLevel() slog.Level

GetLogLevel ...

func SetLogLevel

func SetLogLevel(level string) slog.Level

SetLogLevel ...

Types

type Attr

type Attr = slog.Attr

Attr ...

func ErrAttr

func ErrAttr(err error) Attr

ErrAttr helper func

logger.Error("user msg error", ErrAttr(err))

type Handler

type Handler = slog.Handler

Handler ...

type HandlerOptions

type HandlerOptions = slog.HandlerOptions

HandlerOptions ...

type Level

type Level = slog.Level

Level ...

type LogValuer

type LogValuer = slog.LogValuer

LogValuer ...

type Logger

type Logger = slog.Logger

Logger алиасы типов

func Default

func Default() *Logger

Default ...

func L

func L(ctx context.Context) *Logger

L loggerFromContext

func New

func New(opts ...LoggerOption) *Logger

New create logger

func NewEnv

func NewEnv(env string) *Logger

NewEnv создание логера на основе Env (local, dev, prod)

func WithAttrs

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

WithAttrs returns logger with attributes.

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.

func WithFileLog

func WithFileLog(fileName string) LoggerOption

WithFileLog ...

func WithIsJSON

func WithIsJSON(IsJSON bool) LoggerOption

WithIsJSON ...

func WithLevel

func WithLevel(level string) LoggerOption

WithLevel ...

func WithOnlyFile

func WithOnlyFile(onlyFile bool) LoggerOption

WithOnlyFile ...

func WithWriter

func WithWriter(w io.Writer) LoggerOption

WithWriter ...

type Value

type Value = slog.Value

Value ...

Jump to

Keyboard shortcuts

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