Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferedHandler ¶
type BufferedHandler struct { LevelsWithFormatter // options FlushInterval int // contains filtered or unexported fields }
BufferedHandler definition
func NewBufferedHandler ¶
func NewBufferedHandler(handler slog.WriterHandler, bufSize int) *BufferedHandler
NewBufferedHandler create new BufferedHandler
func (*BufferedHandler) Flush ¶
func (h *BufferedHandler) Flush() error
Flush all buffers to the `h.handler.Writer()`
type ConsoleHandler ¶
type ConsoleHandler struct {
StreamHandler
}
ConsoleHandler definition
func NewConsoleHandler ¶
func NewConsoleHandler(levels []slog.Level) *ConsoleHandler
NewConsoleHandler create new ConsoleHandler
func (*ConsoleHandler) ConfigFormatter ¶
func (h *ConsoleHandler) ConfigFormatter(fn func(formatter *slog.TextFormatter))
SetColorTheme to the formatter
type FileHandler ¶
type FileHandler struct { LevelsWithFormatter // NoBuffer on write log records NoBuffer bool // FileFlag for create. default: os.O_CREATE|os.O_WRONLY|os.O_APPEND FileFlag int // FileMode perm for create log file. (it's os.FileMode) FileMode uint32 // BuffSize for enable buffer BuffSize int // file contents max size MaxSize uint64 // RenameFunc for rotate file RenameFunc func(fpath string) string // contains filtered or unexported fields }
FileHandler definition
func JSONFileHandler ¶
func JSONFileHandler(fpath string) *FileHandler
JSONFileHandler create new FileHandler with JSON formatter
func NewFileHandler ¶
func NewFileHandler(fpath string, useJSON bool) *FileHandler
NewFileHandler create new FileHandler
func (*FileHandler) Close ¶
func (h *FileHandler) Close() error
Close handler, will be flush logs to file, then close file
func (*FileHandler) Configure ¶
func (h *FileHandler) Configure(fn func(h *FileHandler)) *FileHandler
Configure the handler
type GroupedHandler ¶
type GroupedHandler struct { // Levels for log message Levels []slog.Level // IgnoreErr on handling messages IgnoreErr bool // contains filtered or unexported fields }
GroupedHandler definition
func NewGroupedHandler ¶
func NewGroupedHandler(handlers []slog.Handler) *GroupedHandler
NewGroupedHandler create new GroupedHandler
func (*GroupedHandler) Handle ¶
func (h *GroupedHandler) Handle(record *slog.Record) error
Handle log record
func (*GroupedHandler) IsHandling ¶
func (h *GroupedHandler) IsHandling(level slog.Level) bool
IsHandling Check if the current level can be handling
type LevelWithFormatter ¶ added in v0.0.3
type LevelWithFormatter struct { slog.Formattable // Level for log message. if current level >= Level will log message Level slog.Level }
LevelsWithFormatter definition
func (*LevelWithFormatter) Close ¶ added in v0.0.3
func (h *LevelWithFormatter) Close() error
Close handler
func (*LevelWithFormatter) Flush ¶ added in v0.0.3
func (h *LevelWithFormatter) Flush() error
Flush logs to disk
func (*LevelWithFormatter) IsHandling ¶ added in v0.0.3
func (h *LevelWithFormatter) IsHandling(level slog.Level) bool
IsHandling Check if the current level can be handling
type LevelsWithFormatter ¶ added in v0.0.3
type LevelsWithFormatter struct { slog.Formattable // Levels for log message Levels []slog.Level }
LevelsWithFormatter definition
func (*LevelsWithFormatter) Close ¶ added in v0.0.3
func (h *LevelsWithFormatter) Close() error
Close handler
func (*LevelsWithFormatter) Flush ¶ added in v0.0.3
func (h *LevelsWithFormatter) Flush() error
Flush logs to disk
func (*LevelsWithFormatter) IsHandling ¶ added in v0.0.3
func (h *LevelsWithFormatter) IsHandling(level slog.Level) bool
IsHandling Check if the current level can be handling
type MultiFileHandler ¶ added in v0.0.3
type MultiFileHandler struct { // FileDir for save log files FileDir string // Files can use multi file for record level logs. eg: // "error.log": []slog.Level{slog.Warn, slog.Error}, // "info.log": []slog.Level{slog.Trace, slog.Info, slog.Notice} FileLevels map[string][]slog.Level // NoBuffer on write log records NoBuffer bool // FileFlag for create. default: os.O_CREATE|os.O_WRONLY|os.O_APPEND FileFlag int // FileMode perm for create log file. (it's os.FileMode) FileMode uint32 // BuffSize for enable buffer BuffSize int // file contents max size MaxSize uint64 // contains filtered or unexported fields }
MultiFileHandler definition
func NewMultiFileHandler ¶ added in v0.0.3
func NewMultiFileHandler() *MultiFileHandler
NewMultiFileHandler instance
type RotateFileHandler ¶
type RotateFileHandler struct { FileHandler // RenameFunc for rotate file RenameFunc func(fpath string) string // contains filtered or unexported fields }
RotateFileHandler definition
type StreamHandler ¶
type StreamHandler struct { LevelsWithFormatter // Output io.WriteCloser Output io.Writer UseLock bool }
StreamHandler definition
func NewStreamHandler ¶
func NewStreamHandler(out io.Writer, levels []slog.Level) *StreamHandler
NewStreamHandler create new StreamHandler