云盘
志元云盘
备份云盘
Home
/
志元云盘
/
webdav
/
sync
/
go
/
pkg
/
mod
/
github.com
/
sirupsen
/
[email protected]
/
hooks
/
writer
File
OriginalPic
Thumbnails
CopyAllDownloadUrl
EditTime
Size
README.md
2024-10-15 11:06:26
896 B
writer.go
2024-10-15 11:06:26
650 B
writer_test.go
2024-10-15 11:06:26
774 B
# Writer Hooks for Logrus Send logs of given levels to any object with `io.Writer` interface. ## Usage If you want for example send high level logs to `Stderr` and logs of normal execution to `Stdout`, you could do it like this: ```go package main import ( "io/ioutil" "os" log "github.com/sirupsen/logrus" "github.com/sirupsen/logrus/hooks/writer" ) func main() { log.SetOutput(ioutil.Discard) // Send all logs to nowhere by default log.AddHook(&writer.Hook{ // Send logs with level higher than warning to stderr Writer: os.Stderr, LogLevels: []log.Level{ log.PanicLevel, log.FatalLevel, log.ErrorLevel, log.WarnLevel, }, }) log.AddHook(&writer.Hook{ // Send info and debug logs to stdout Writer: os.Stdout, LogLevels: []log.Level{ log.InfoLevel, log.DebugLevel, }, }) log.Info("This will go to stdout") log.Warn("This will go to stderr") } ```
2025-09-05 13:00:13 Friday 216.73.216.148 Runningtime:0.014s Mem:1.47 MB