Skip to content

Latest commit

 

History

History

handler

Handlers

Package handler provide useful common log handlers. eg: file, console, multi_file, rotate_file, stream, syslog, email

handler -> buffered -> rotated -> writer(os.File)

Built-in handlers

  • handler.ConsoleHandler Console handler
  • handler.FileHandler File handler
  • handler.StreamHandler Stream handler
  • handler.SyslogHandler Syslog handler
  • handler.EmailHandler Email handler
  • handler.FlushCloseHandler Flush and close handler

Go Docs

Docs generated by: go doc ./handler

Handler Functions

func LineBuffOsFile(f *os.File, bufSize int, levels []slog.Level) slog.Handler
func LineBuffWriter(w io.Writer, bufSize int, levels []slog.Level) slog.Handler
func LineBufferedFile(logfile string, bufSize int, levels []slog.Level) (slog.Handler, error)

type ConsoleHandler = IOWriterHandler
    func ConsoleWithLevels(levels []slog.Level) *ConsoleHandler
    func ConsoleWithMaxLevel(level slog.Level) *ConsoleHandler
    func NewConsole(levels []slog.Level) *ConsoleHandler
    func NewConsoleHandler(levels []slog.Level) *ConsoleHandler
    func NewConsoleWithLF(lf slog.LevelFormattable) *ConsoleHandler
type EmailHandler struct{ ... }
    func NewEmailHandler(from EmailOption, toAddresses []string) *EmailHandler
type EmailOption struct{ ... }

type FlushCloseHandler struct{ ... }
    func FlushCloserWithLevels(out FlushCloseWriter, levels []slog.Level) *FlushCloseHandler
    func FlushCloserWithMaxLevel(out FlushCloseWriter, maxLevel slog.Level) *FlushCloseHandler
    func NewBuffered(w io.WriteCloser, bufSize int, levels ...slog.Level) *FlushCloseHandler
    func NewBufferedHandler(w io.WriteCloser, bufSize int, levels ...slog.Level) *FlushCloseHandler
    func NewFlushCloseHandler(out FlushCloseWriter, levels []slog.Level) *FlushCloseHandler
    func NewFlushCloser(out FlushCloseWriter, levels []slog.Level) *FlushCloseHandler
    func NewFlushCloserWithLF(out FlushCloseWriter, lf slog.LevelFormattable) *FlushCloseHandler

type IOWriterHandler struct{ ... }
    func IOWriterWithLevels(out io.Writer, levels []slog.Level) *IOWriterHandler
    func IOWriterWithMaxLevel(out io.Writer, maxLevel slog.Level) *IOWriterHandler
    func NewIOWriter(out io.Writer, levels []slog.Level) *IOWriterHandler
    func NewIOWriterHandler(out io.Writer, levels []slog.Level) *IOWriterHandler
    func NewIOWriterWithLF(out io.Writer, lf slog.LevelFormattable) *IOWriterHandler
    func NewSimpleHandler(out io.Writer, maxLevel slog.Level) *IOWriterHandler
    func SimpleWithLevels(out io.Writer, levels []slog.Level) *IOWriterHandler


type SimpleHandler = IOWriterHandler
    func NewHandler(out io.Writer, maxLevel slog.Level) *SimpleHandler
    func NewSimple(out io.Writer, maxLevel slog.Level) *SimpleHandler

type SyncCloseHandler struct{ ... }
    func JSONFileHandler(logfile string, fns ...ConfigFn) (*SyncCloseHandler, error)
    func MustFileHandler(logfile string, fns ...ConfigFn) *SyncCloseHandler
    func MustRotateFile(logfile string, rt rotatefile.RotateTime, fns ...ConfigFn) *SyncCloseHandler
    func MustSimpleFile(filepath string, maxLv ...slog.Level) *SyncCloseHandler
    func MustSizeRotateFile(logfile string, maxSize int, fns ...ConfigFn) *SyncCloseHandler
    func MustTimeRotateFile(logfile string, rt rotatefile.RotateTime, fns ...ConfigFn) *SyncCloseHandler
    func NewBuffFileHandler(logfile string, buffSize int, fns ...ConfigFn) (*SyncCloseHandler, error)
    func NewFileHandler(logfile string, fns ...ConfigFn) (h *SyncCloseHandler, err error)
    func NewRotateFile(logfile string, rt rotatefile.RotateTime, fns ...ConfigFn) (*SyncCloseHandler, error)
    func NewRotateFileHandler(logfile string, rt rotatefile.RotateTime, fns ...ConfigFn) (*SyncCloseHandler, error)
    func NewSimpleFile(filepath string, maxLv ...slog.Level) (*SyncCloseHandler, error)
    func NewSimpleFileHandler(filePath string, maxLv ...slog.Level) (*SyncCloseHandler, error)
    func NewSizeRotateFile(logfile string, maxSize int, fns ...ConfigFn) (*SyncCloseHandler, error)
    func NewSizeRotateFileHandler(logfile string, maxSize int, fns ...ConfigFn) (*SyncCloseHandler, error)
    func NewSyncCloseHandler(out SyncCloseWriter, levels []slog.Level) *SyncCloseHandler
    func NewSyncCloser(out SyncCloseWriter, levels []slog.Level) *SyncCloseHandler
    func NewSyncCloserWithLF(out SyncCloseWriter, lf slog.LevelFormattable) *SyncCloseHandler
    func NewTimeRotateFile(logfile string, rt rotatefile.RotateTime, fns ...ConfigFn) (*SyncCloseHandler, error)
    func NewTimeRotateFileHandler(logfile string, rt rotatefile.RotateTime, fns ...ConfigFn) (*SyncCloseHandler, error)
    func SyncCloserWithLevels(out SyncCloseWriter, levels []slog.Level) *SyncCloseHandler
    func SyncCloserWithMaxLevel(out SyncCloseWriter, maxLevel slog.Level) *SyncCloseHandler

type SysLogHandler struct{ ... }
    func NewSysLogHandler(priority syslog.Priority, tag string) (*SysLogHandler, error)

type WriteCloserHandler struct{ ... }
    func NewWriteCloser(out io.WriteCloser, levels []slog.Level) *WriteCloserHandler
    func NewWriteCloserHandler(out io.WriteCloser, levels []slog.Level) *WriteCloserHandler
    func NewWriteCloserWithLF(out io.WriteCloser, lf slog.LevelFormattable) *WriteCloserHandler
    func WriteCloserWithLevels(out io.WriteCloser, levels []slog.Level) *WriteCloserHandler
    func WriteCloserWithMaxLevel(out io.WriteCloser, maxLevel slog.Level) *WriteCloserHandler

Config Functions

type Builder struct{ ... }
    func NewBuilder() *Builder
type Config struct{ ... }
    func NewConfig(fns ...ConfigFn) *Config
    func NewEmptyConfig(fns ...ConfigFn) *Config
type ConfigFn func(c *Config)
    func WithBackupNum(n uint) ConfigFn
    func WithBackupTime(bt uint) ConfigFn
    func WithBuffMode(buffMode string) ConfigFn
    func WithBuffSize(buffSize int) ConfigFn
    func WithCompress(compress bool) ConfigFn
    func WithFilePerm(filePerm fs.FileMode) ConfigFn
    func WithLevelMode(mode slog.LevelMode) ConfigFn
    func WithLevelNames(names []string) ConfigFn
    func WithLogLevel(level slog.Level) ConfigFn
    func WithLogLevels(levels slog.Levels) ConfigFn
    func WithLogfile(logfile string) ConfigFn
    func WithMaxSize(maxSize uint64) ConfigFn
    func WithRotateMode(m rotatefile.RotateMode) ConfigFn
    func WithRotateTime(rt rotatefile.RotateTime) ConfigFn
    func WithUseJSON(useJSON bool) ConfigFn