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")
}
4 Comments
FLY的狐狸
既有write接口实现又有handler方式,是后续都建议使用handler还是两种适应的场景不同?
小陈
我有个疑问, 假如不是异步的话, 这样访问网络, 应该很慢吧.
糖水不加糖
自行异步化处理就可以
小陈
有道理, 谢谢大佬.