Use this hook to send the logs to Logstash over both UDP and TCP.
package main
import (
"github.com/Sirupsen/logrus"
"github.com/bshuster-repo/logrus-logstash-hook"
)
func main() {
log := logrus.New()
hook, err := logrus_logstash.NewHook("tcp", "172.17.0.2:9999", "myappName")
if err != nil {
log.Fatal(err)
}
log.Hooks.Add(hook)
ctx := log.WithFields(logrus.Fields{
"method": "main",
})
...
ctx.Info("Hello World!")
}
This is how it will look like:
{
"@timestamp" => "2016-02-29T16:57:23.000Z",
"@version" => 1,
"level" => "info",
"message" => "Hello World!",
"method" => "main",
"host" => "172.17.0.1",
"port" => 45199,
"type" => "myappName"
}