package logging
import (
logger "github.com/sirupsen/logrus"
"gopkg.in/natefinch/lumberjack.v2"
"io"
)
type ApplicationHookConfig struct {
Filename string
MaxSize int
MaxBackups int
MaxAge int
Level logger.Level
Formatter logger.Formatter
}
type ApplicationHook struct {
cfg ApplicationHookConfig
logWriter io.Writer
}
func NewApplicationHook(config ApplicationHookConfig) logger.Hook {
return &ApplicationHook{
cfg: config,
logWriter: &lumberjack.Logger{
Filename: config.Filename,
MaxSize: config.MaxSize,
MaxBackups: config.MaxBackups,
MaxAge: config.MaxAge,
},
}
}
func (s *ApplicationHook) Levels() []logger.Level {
return logger.AllLevels
}
func (s *ApplicationHook) Fire(entry *logger.Entry) error {
b, err := s.cfg.Formatter.Format(entry)
if err != nil {
return err
}
_, err = s.logWriter.Write(b)
return err
}
|
The pages are generated with Golds v0.3.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |