Giter VIP home page Giter VIP logo

Comments (13)

boaz0 avatar boaz0 commented on June 3, 2024

Hi 👋 @mohammadinasab-dev

Can you attach Logstash configuration as well?

from logrus-logstash-hook.

mohammadinasab-dev avatar mohammadinasab-dev commented on June 3, 2024

hi @boaz0
and thank for your attentions...

input{
    tcp{
       host => "127.0.0.1"
       port => 8911
       mode => server
       codec => json
    }
}

filter{
    json{
        source => "message"
    }
}
output{
    elasticsearch{
	hosts => "http://localhost:9200/"
	index => "j-06-json"
    }
}

from logrus-logstash-hook.

boaz0 avatar boaz0 commented on June 3, 2024

Hi @mohammadinasab-dev I was trying to reproduce this bug but unfortunately I can not.

This is what I get:

{"@version":"1","level":"info","method":"main","type":"myappName","host":"localhost","message":"Hello World in print again!","@timestamp":"2021-06-21T16:23:58.000Z"}

I believe this is something related to how you configured the networking on the server.
If you can specify what command line you were executing, I may help you.

from logrus-logstash-hook.

mohammadinasab-dev avatar mohammadinasab-dev commented on June 3, 2024

@boaz0
thank you again,
i'm at windows and i use CMD to run logstash (ELK)
and another things to mention is that i have the log in stdout but i dont have it in logstash! until i add time delay.

from logrus-logstash-hook.

boaz0 avatar boaz0 commented on June 3, 2024

@mohammadinasab-dev maybe that's the problem.
I am running Linux and even without the time.Sleep I can see the logs.

Can you try to do

func main() {
	log := logrus.New()
	conn, err := net.Dial("tcp", "127.0.0.1:8911")
	if err != nil || conn == 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",
	})
        for i := 0; i < 10; i++ {
            ctx.Info("Hello ", i)
        }
}

Do you see any logs and how many lines?

from logrus-logstash-hook.

mohammadinasab-dev avatar mohammadinasab-dev commented on June 3, 2024

@boaz0 yes maybe the windows is the problem!
it works as explain below:
i try your code many times and after 2nd or 3rd i have all 10 in both stdout and ES too!
and at the first time nothing then at the second time for example 9 and for 3rd tries and more i have exactly 10!
and it's better to say that after many times that i run the code it works correct but for very first tries it doesn't work correctly!

from logrus-logstash-hook.

shojaeix avatar shojaeix commented on June 3, 2024

Hi @mohammadinasab-dev
Can you put a log.Exit(1) at the end of your main function and see if it makes any difference?

from logrus-logstash-hook.

mohammadinasab-dev avatar mohammadinasab-dev commented on June 3, 2024

Hi @shojaeix and thanks for your attention
yes i did and nothing changes, just it works correct in for loop, or running the program fast and continuously for many times(it looks like a manual looping!).
am i correct by your mean?
‍‍‍‍```
func main() {
log := logrus.New()
conn, err := net.Dial("tcp", "127.0.0.1:8911")
if err != nil || conn == 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",
})
// for i := 0; i < 10; i++ {
// 	ctx.Info("Hello", i)
// }
ctx.Info("hello")
log.Exit(1)

}

from logrus-logstash-hook.

shojaeix avatar shojaeix commented on June 3, 2024

Hi @shojaeix and thanks for your attention
yes i did and nothing changes, just it works correct in for loop, or running the program fast and continuously for many times(it looks like a manual looping!).
am i correct by your mean?
‍‍‍‍```
func main() {
log := logrus.New()
conn, err := net.Dial("tcp", "127.0.0.1:8911")
if err != nil || conn == 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",
})
// for i := 0; i < 10; i++ {
// ctx.Info("Hello", i)
// }
ctx.Info("hello")
log.Exit(1)

}```

I though this function will wait and write all logs before exiting.

from logrus-logstash-hook.

boaz0 avatar boaz0 commented on June 3, 2024

@mohammadinasab-dev I believe this is probably a non-deterministic behavior on behalf of Go.
Would you mind opening a ticket on Go repository and see what they think?

Thanks.

from logrus-logstash-hook.

mohammadinasab-dev avatar mohammadinasab-dev commented on June 3, 2024

@shojaeix it seems to be, but it wasn't wait!!

from logrus-logstash-hook.

mohammadinasab-dev avatar mohammadinasab-dev commented on June 3, 2024

@boaz0 my go version is 1.15.2 maybe i should upgrade it to latest, and a ticket on go repository is good idea, anyway thank you again .

from logrus-logstash-hook.

boaz0 avatar boaz0 commented on June 3, 2024

You're welcome. I will colse this issue but feel free to re-open it if you disagree.

Let me know if there is any update. I would like to know what was the problem and how this plugin can help with this.

Thanks.

from logrus-logstash-hook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.