Socket hook for logrus
Use this hook to send the logs over UDP, TCP or Unix socket.
Output format is JSON, formatted for Logstash/ElasticSearch.
package main
import (
"github.com/sirupsen/logrus"
"github.com/Showmax/sockrus"
)
func main() {
log := logrus.New()
hook, err := sockrus.NewHook("unixpacket", "/tmp/log.sock")
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-04-15T12:49:36Z",
"@version": 1,
"level": "info",
"message": "Hello World!",
"method": "main"
}