package main
import (
"context"
"github.com/gogf/gf/v2/os/glog"
"github.com/robertkowalski/graylog-golang"
)
type MyGrayLogWriter struct {
gelf *gelf.Gelf
logger *glog.Logger
}
func (w *MyGrayLogWriter) Write(p []byte) (n int, err error) {
w.gelf.Send(p)
return w.logger.Write(p)
}
func main() {
var ctx = context.Background()
glog.SetWriter(&MyGrayLogWriter{
logger : glog.New(),
gelf : gelf.New(gelf.Config{
GraylogPort : 80,
GraylogHostname : "graylog-host.com",
Connection : "wan",
MaxChunkSizeWan : 42,
MaxChunkSizeLan : 1337,
}),
})
glog.Println(ctx, "test log")
}
1 Comment
FLY的狐狸
既有write接口实现又有handler方式,是后续都建议使用handler还是两种适应的场景不同?