2020-09-01 00:26:57 +00:00
|
|
|
# Logstash hook for logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:" />
|
|
|
|
[![Build Status](https://travis-ci.org/bshuster-repo/logrus-logstash-hook.svg?branch=master)](https://travis-ci.org/bshuster-repo/logrus-logstash-hook)
|
|
|
|
[![Go Report Status](https://goreportcard.com/badge/github.com/bshuster-repo/logrus-logstash-hook)](https://goreportcard.com/report/github.com/bshuster-repo/logrus-logstash-hook)
|
2017-04-10 19:07:32 +00:00
|
|
|
|
2020-09-01 00:26:57 +00:00
|
|
|
Use this hook to send the logs to [Logstash](https://www.elastic.co/products/logstash).
|
|
|
|
|
|
|
|
# Usage
|
2017-04-10 19:07:32 +00:00
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/bshuster-repo/logrus-logstash-hook"
|
2020-09-01 00:26:57 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"net"
|
2017-04-10 19:07:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
log := logrus.New()
|
2020-09-01 00:26:57 +00:00
|
|
|
conn, err := net.Dial("tcp", "logstash.mycompany.net:8911")
|
2017-04-10 19:07:32 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2020-09-01 00:26:57 +00:00
|
|
|
hook := logrustash.New(conn, logrustash.DefaultFormatter(logrus.Fields{"type": "myappName"}))
|
|
|
|
|
2017-04-10 19:07:32 +00:00
|
|
|
log.Hooks.Add(hook)
|
|
|
|
ctx := log.WithFields(logrus.Fields{
|
2020-09-01 00:26:57 +00:00
|
|
|
"method": "main",
|
2017-04-10 19:07:32 +00:00
|
|
|
})
|
|
|
|
ctx.Info("Hello World!")
|
|
|
|
}
|
2020-09-01 00:26:57 +00:00
|
|
|
|
2017-04-10 19:07:32 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
This is how it will look like:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
{
|
|
|
|
"@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"
|
|
|
|
}
|
|
|
|
```
|
2017-06-23 19:45:04 +00:00
|
|
|
|
2020-09-01 00:26:57 +00:00
|
|
|
# Maintainers
|
2017-06-23 19:45:04 +00:00
|
|
|
|
|
|
|
Name | Github | Twitter |
|
|
|
|
------------ | --------- | ---------- |
|
|
|
|
Boaz Shuster | ripcurld0 | @ripcurld0 |
|
|
|
|
|
|
|
|
# License
|
|
|
|
|
|
|
|
MIT.
|