Open bencromwell opened 1 month ago
I moved this call into a goroutine, to prevent blocking the main thread.
After reviewing the library, I confirm a potential blocking behavior when you write to the socket.
I would suggest an update of the Graylog lib, to add buffering, followed by a defer graylog.Close()
in your program, to flush before exiting.
WDYT?
Would this library need to change to depend on an interface in order to support such a change?
If github.com/Graylog2/go-gelf
could buffer logs and flush periodically to the connection, this slog-graylog lib would be non-blocking without goroutine.
But go-gelf would need a method to flush before program exit as well.
Hello,
In
handler.go
there is a goroutine for writing the message.I'm finding that when a program attempts to write to Graylog immediately before it exits (such as a final error message), that message consistently never makes it to Graylog. The goroutines are all cancelled as soon as it exits, so it never finishes.
Changing this to just:
Does ensure the logs are written. However, I assume it was made into a routine for a reason.
Is there a better way to resolve this?