代码拉取完成,页面将自动刷新
Use this hook to send your logs to Graylog server over UDP. The hook is non-blocking: even if UDP is used to send messages, the extra work should not block the logging function.
All logrus fields will be sent as additional fields on Graylog.
The hook must be configured with:
package main
import (
log "github.com/sirupsen/logrus"
"github.com/gemnasium/logrus-graylog-hook/v3"
)
func main() {
hook := graylog.NewGraylogHook("<graylog_ip>:<graylog_port>", map[string]interface{}{"this": "is logged every time"})
log.AddHook(hook)
log.Info("some logging message")
}
package main
import (
log "github.com/sirupsen/logrus"
"github.com/gemnasium/logrus-graylog-hook/v3"
)
func main() {
hook := graylog.NewAsyncGraylogHook("<graylog_ip>:<graylog_port>", map[string]interface{}{"this": "is logged every time"})
defer hook.Flush()
log.AddHook(hook)
log.Info("some logging message")
}
For some reason, you may want to disable logging on stdout, and keep only the messages in Graylog (ie: a webserver inside a docker container).
You can redirect stdout
to /dev/null
, or just not log anything by creating a NullFormatter
implementing logrus.Formatter
interface:
type NullFormatter struct {
}
// Don't spend time formatting logs
func (NullFormatter) Format(e *log.Entry) ([]byte, error) {
return []byte{}, nil
}
And set this formatter as the new logging formatter:
log.Infof("Log messages are now sent to Graylog (udp://%s)", graylogAddr) // Give a hint why logs are empty
log.AddHook(graylog.NewGraylogHook(graylogAddr, "api", map[string]interface{}{})) // set graylogAddr accordingly
log.SetFormatter(new(NullFormatter)) // Don't send logs to stdout
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。