Categorygithub.com/alc6/logrus-logstash-hook
modulepackage
1.0.3
Repository: https://github.com/alc6/logrus-logstash-hook.git
Documentation: pkg.go.dev

# README

Build Status Go Report Card

Logstash hook for logrus :walrus:

This repository is a fork of https://github.com/bshuster-repo/logrus-logstash-hook, with opinionated changes related to logrus/logstash.

Basically, you might be interested in this fork if you're likely to use logrus with the Report Caller, and if you want a ns precision on the logs sent to logstash.

All the credit of the work is given to Boaz Shuster.

Use this hook to send the logs to Logstash.

Usage

package main

import (
        "github.com/bshuster-repo/logrus-logstash-hook"
        "github.com/sirupsen/logrus"
        "net"
)

func main() {
        log := logrus.New()
        conn, err := net.Dial("tcp", "logstash.mycompany.net:8911")
        if err != nil {
                log.Fatal(err)
        }
        hook := logrustash.New(conn, logrustash.DefaultFormatter(logrus.Fields{"type": "myappName"}))

        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.456Z",
      "@version" => "1",
         "level" => "info",
       "message" => "Hello World!",
        "method" => "main",
          "host" => "172.17.0.1",
          "port" => 45199,
          "type" => "myappName"
}

This is how it will look like with report caller enabled:

{
    "@timestamp" => "2016-02-29T16:57:23.456Z",
      "@version" => "1",
         "level" => "info",
       "message" => "Hello World!",
        "method" => "main",
          "host" => "172.17.0.1",
          "port" => 45199,
          "type" => "myappName"
          "file" => "github.com/user/project/main.go:10"
          "func" => "github.com/user/project/moduleMain.Func
}

Maintainers

NameGithubTwitter
Boaz Shusterripcurld0@ripcurld0

License

Boaz Shuster/MIT.

# Functions

DefaultFormatter returns a default Logstash formatter: A JSON format with "@version" set to "1" (unless set differently in `fields`, "type" to "log" (unless set differently in `fields`), "@timestamp" to the log time and "message" to the log message.
New returns a new logrus.Hook for Logstash.

# Structs

Hook represents a Logstash hook.
LogstashFormatter represents a Logstash format.