package logging
import (
logger "github.com/sirupsen/logrus"
"io"
"os"
)
type StdoutHook struct {
Level logger.Level
Formatter logger.Formatter
}
func NewStdoutHook(level logger.Level, formatter logger.Formatter) logger.Hook {
return StdoutHook{level, formatter}
}
func (s StdoutHook) Levels() []logger.Level {
return logger.AllLevels
}
func (s StdoutHook) Fire(entry *logger.Entry) error {
if s.Level >= entry.Level {
b, err := s.Formatter.Format(entry)
if err != nil {
return err
}
if _, err = io.WriteString(os.Stdout, string(b)); err != nil {
return err
}
}
return nil
}
|
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. |