dahankzter / logrus-logstash-hook

Logstash hook for logrus

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Logstash hook for logrus :walrus: Build Status

Use this hook to send the logs to Logstash over both UDP and TCP.

Usage

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")
        // OR use NewHookWithFields to always send specific fields with every log entry
        hook, err := logrus_logstash.NewHookWithFields("tcp", "172.17.0.2:9999", "myappName", logrus.Fields{
                "hostname":    os.Hostname(),
                "serviceName": "myServiceName",
        })
        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"
}

About

Logstash hook for logrus

License:MIT License


Languages

Language:Go 100.0%