go-kit log write to a file or any third party logger application

955 views
Skip to first unread message

mail...@gmail.com

unread,
Jan 17, 2018, 4:07:52 AM1/17/18
to Go kit
Hello,

     I am new and trying to use go-kit log for my application. How can I configure go-kit log to write output to both stdout/stderr and log file on the file (such as syslog or any other  file) ? Does go-kit provides a way to send log to third party application such as Logstash ?


Thanks

Gulácsi Tamás

unread,
Jan 17, 2018, 4:25:46 AM1/17/18
to mail...@gmail.com, Go kit
As the logger only needs an io.Writer, that io.Writer can be an io.MultiWriter, which writes to os.Stderr, os.Stdout, an *os.File, whatever.
For logstash: in 5 minutes, I haven't found a ready solution (an abandoned, but simple to clean up: https://github.com/heatxsink/go-logstash, an over-engineered: https://godoc.org/github.com/elastic/beats/libbeat/outputs#Load), but the format is really easy: https://github.com/zendesk/go-httpclerk/blob/master/logstash_formatter.go


--
You received this message because you are subscribed to the Google Groups "Go kit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to go-kit+un...@googlegroups.com.
To post to this group, send email to go-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/go-kit/9ab246c9-5582-4c4b-9f86-773e26649ae0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mail...@gmail.com

unread,
Jan 17, 2018, 11:42:52 PM1/17/18
to Go kit
Thanks Tamas, Is it possible to write both in console and file or send to third party log collector?

Tamás Gulácsi

unread,
Jan 18, 2018, 12:46:52 AM1/18/18
to Go kit
2018. január 18., csütörtök 5:42:52 UTC+1 időpontban mail...@gmail.com a következőt írta:
Thanks Tamas, Is it possible to write both in console and file or send to third party log collector?


Yes.

For example to write to stderr (console) + a file:

logFh, err := os.Create("my.log")
if err != nil {
    panic(err)
}
defer logFh.Close()
logger := log.NewLogfmtLogger(io.MultiWriter(os.Stderr, fh))
logger.Log("msg", "a message")
Reply all
Reply to author
Forward
0 new messages