handler

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: MIT Imports: 13 Imported by: 21

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) Close

func (h *BufferedHandler) Close() error

Close log records

func (*BufferedHandler) Flush

func (h *BufferedHandler) Flush() error

Flush all buffers to the `h.handler.Writer()`

func (*BufferedHandler) Handle

func (h *BufferedHandler) Handle(record *slog.Record) error

Handle log record

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

func (*FileHandler) Flush

func (h *FileHandler) Flush() error

Flush logs to disk file

func (*FileHandler) Handle

func (h *FileHandler) Handle(r *slog.Record) (err error)

Handle the log record

func (*FileHandler) Writer

func (h *FileHandler) Writer() io.Writer

Writer return *os.File

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) Close

func (h *GroupedHandler) Close() error

Close log handlers

func (*GroupedHandler) Flush

func (h *GroupedHandler) Flush() error

Flush log records

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

func (*RotateFileHandler) Write

func (h *RotateFileHandler) Write(p []byte) (n int, err error)

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

func (*StreamHandler) Close

func (h *StreamHandler) Close() error

Close the handler

func (*StreamHandler) Handle

func (h *StreamHandler) Handle(record *slog.Record) error

Handle log record

type SysLog added in v0.0.3

type SysLog struct {
	LevelsWithFormatter
	// contains filtered or unexported fields
}

func NewSysLog added in v0.0.3

func NewSysLog(priority syslog.Priority, tag string) *SysLog

func (*SysLog) Handle added in v0.0.3

func (h *SysLog) Handle(record *slog.Record) error

Jump to

Keyboard shortcuts

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