Reconnect to logstash on connection timeout · Issue #48 · bshuster-repo/logrus-logstash-hook (original) (raw)

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

pseudonem opened this issue

Nov 17, 2017

· 4 comments

Comments

@pseudonem

After long stretches of inactivity our logstash connection times out with the following errors:

Failed to fire hook: write tcp 10.0.0.212:45992->10.0.4.98:5000: write: connection timed out
Failed to fire hook: write tcp 10.0.0.212:45992->10.0.4.98:5000: write: broken pipe

As such, logs are no longer written. Is there any way to have the logstash hook automatically retry the connection?

@boaz0

@pseudonem thanks so much for your interest in this project 👍 .
This is something that we definitely need in the package. However, I don't have much time to work on this. If you have time please feel free to submit a pull request.

Best regards.

@jgiannuzzi

A way to solve this is to use the GoAutoSocket package: http://github.com/firstrow/goautosocket

Create your TCP connection with gas.Dial and pass it lo logrustash.NewHookWithConn (or any other WithConn variant):

package main

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

func main() { log := logrus.New()

conn, err := gas.Dial("tcp", "172.17.0.2:9999") if err != nil { log.Fatal(err) }

hook, err := logrustash.NewHookWithConn(conn, "myappName") if err != nil { log.Fatal(err) } log.Hooks.Add(hook) ctx := log.WithFields(logrus.Fields{ "method": "main", }) ... ctx.Info("Hello World!") }

@boaz0

@eloo

@jgiannuzzi thanks for this snippets.. works pretty good for me..
can this maybe be added to the readme?