wlog

package
v0.0.0-...-2ec8670 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

wlog is a wrapped logger

Index

Constants

This section is empty.

Variables

Functions

func NewHandler

func NewHandler(w io.Writer, noColor bool, conf *Config) slog.Handler

func NewRotateWriter

func NewRotateWriter(filename string, bufSize int) (io.WriteCloser, error)

Types

type Config

type Config struct {
	// Debug = -4
	// Info  = 0
	// Warn  = 4
	// Error = 8
	Level *int `yaml:"Level"`

	AddSource  *bool `yaml:"AddSource"`
	JsonFormat *bool `yaml:"JsonFormat"`

	Formats  []FormatFunc   `yaml:"-" json:"-"`
	LevelVar *slog.LevelVar `yaml:"-" json:"-"`
}

func (*Config) SetAddSource

func (conf *Config) SetAddSource(add bool) *Config

func (*Config) SetFormats

func (conf *Config) SetFormats(formats ...FormatFunc) *Config

func (*Config) SetJsonFormat

func (conf *Config) SetJsonFormat(json bool) *Config

func (*Config) SetLevelVar

func (conf *Config) SetLevelVar(level int) *Config

type FormatFunc

type FormatFunc func(groups []string, a slog.Attr) (slog.Attr, bool)

func FormatKeySource

func FormatKeySource() FormatFunc

func FormatKindDuration

func FormatKindDuration() FormatFunc

func FormatKindTime

func FormatKindTime() FormatFunc

func FormatTypeFunc

func FormatTypeFunc() FormatFunc

type Logger

type Logger struct {
	*slog.Logger
	// contains filtered or unexported fields
}

func NewConsoleLogger

func NewConsoleLogger(w io.Writer, conf *Config) *Logger

func NewFileLogger

func NewFileLogger(w io.Writer, conf *Config) *Logger

func NewLogger

func NewLogger(lvl *slog.LevelVar, handlers ...slog.Handler) *Logger

func NewStderrLogger

func NewStderrLogger(conf *Config) *Logger

func NewStderrLoggerWhenDebug

func NewStderrLoggerWhenDebug() *Logger

func NewStderrLoggerWhenIntegrationTest

func NewStderrLoggerWhenIntegrationTest() *Logger

func NewStderrLoggerWhenNormal

func NewStderrLoggerWhenNormal(source bool) *Logger

func (*Logger) CtxGetLogger

func (l *Logger) CtxGetLogger(ctx context.Context) (logger *slog.Logger)

func (*Logger) CtxWithLogger

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

func (*Logger) Level

func (l *Logger) Level() slog.Level

func (*Logger) PointToNew

func (l *Logger) PointToNew(new *Logger)

PointToNew 通過改變指標的指向, 讓所有引用此指標的其他元件獲得最新的狀態

以下是命名方式的分類

改變指標本身: Replace, Set

改變指標的指向: Redirect, PointTo

func (*Logger) SetLevel

func (l *Logger) SetLevel(lvl slog.Level)

func (*Logger) SetStdDefaultLevel

func (l *Logger) SetStdDefaultLevel()

func (*Logger) SetStdDefaultLogger

func (l *Logger) SetStdDefaultLogger()

SetStdDefaultLogger 將標準庫的預設值, 以我方的物件為基準, 控制 logger 行為

type RotateWriter

type RotateWriter struct {
	Logger *slog.Logger
	// contains filtered or unexported fields
}

func (*RotateWriter) Close

func (w *RotateWriter) Close() (err error)

func (*RotateWriter) Write

func (w *RotateWriter) Write(p []byte) (nn int, err error)

Jump to

Keyboard shortcuts

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