Documentation ¶
Overview ¶
wlog is a wrapped logger
Index ¶
- Variables
- func NewHandler(w io.Writer, noColor bool, conf *Config) slog.Handler
- func NewRotateWriter(filename string, bufSize int) (io.WriteCloser, error)
- type Config
- type FormatFunc
- type Logger
- func NewConsoleLogger(w io.Writer, conf *Config) *Logger
- func NewFileLogger(w io.Writer, conf *Config) *Logger
- func NewLogger(lvl *slog.LevelVar, handlers ...slog.Handler) *Logger
- func NewStderrLogger(conf *Config) *Logger
- func NewStderrLoggerWhenDebug() *Logger
- func NewStderrLoggerWhenIntegrationTest() *Logger
- func NewStderrLoggerWhenNormal(source bool) *Logger
- func (l *Logger) CtxGetLogger(ctx context.Context) (logger *slog.Logger)
- func (l *Logger) CtxWithLogger(ctx context.Context, v *slog.Logger) context.Context
- func (l *Logger) Level() slog.Level
- func (l *Logger) PointToNew(new *Logger)
- func (l *Logger) SetLevel(lvl slog.Level)
- func (l *Logger) SetStdDefaultLevel()
- func (l *Logger) SetStdDefaultLogger()
- type RotateWriter
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultFormats = []FormatFunc{ FormatKeySource(), FormatKindTime(), FormatKindDuration(), FormatTypeFunc(), }
Functions ¶
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 (*Config) SetFormats ¶
func (conf *Config) SetFormats(formats ...FormatFunc) *Config
func (*Config) SetJsonFormat ¶
func (*Config) SetLevelVar ¶
type FormatFunc ¶
func FormatKeySource ¶
func FormatKeySource() FormatFunc
func FormatKindDuration ¶
func FormatKindDuration() FormatFunc
func FormatKindTime ¶
func FormatKindTime() FormatFunc
func FormatTypeFunc ¶
func FormatTypeFunc() FormatFunc
type Logger ¶
func NewStderrLogger ¶
func NewStderrLoggerWhenDebug ¶
func NewStderrLoggerWhenDebug() *Logger
func NewStderrLoggerWhenIntegrationTest ¶
func NewStderrLoggerWhenIntegrationTest() *Logger
func (*Logger) CtxGetLogger ¶
func (*Logger) CtxWithLogger ¶
func (*Logger) PointToNew ¶
PointToNew 通過改變指標的指向, 讓所有引用此指標的其他元件獲得最新的狀態
以下是命名方式的分類
改變指標本身: Replace, Set
改變指標的指向: Redirect, PointTo
func (*Logger) SetStdDefaultLevel ¶
func (l *Logger) SetStdDefaultLevel()
func (*Logger) SetStdDefaultLogger ¶
func (l *Logger) SetStdDefaultLogger()
SetStdDefaultLogger 將標準庫的預設值, 以我方的物件為基準, 控制 logger 行為
type RotateWriter ¶
func (*RotateWriter) Close ¶
func (w *RotateWriter) Close() (err error)
Click to show internal directories.
Click to hide internal directories.