Collect logs from your Go application.
Add slog-betterstack to your project dependencies using go get.
Configure slog-betterstack as a handler in a new slog logger.
Your log events will be sent to Better Stack automatically.
You should see your logs in Better Stack β Live tail.
Logs are sent in batches in the background. handler.Close() sends the logs still queued and waits up to 15 seconds for them. os.Exit and log.Fatal skip deferred calls, so close the handler before calling them.
Delivery failures, such as a rejected source token, are printed to stderr. Set OnError to handle them yourself.
Huge thanks to Samuel Berthe who created the slog-betterstack library as an MIT-licensed open-source! β€οΈ
You can use structured data in slog and send context along with your logs.
For more details check out the slog official documentation.
Fine-tune delivery with more fields of slogbetterstack.Option. See the package reference for all of them.
Handler options
Minimum level of the logs sent to Better Stack.
Number of logs sent in one request.
How long a partial batch waits before it is sent.
Retries after a failed request, for timeouts, rate limits, server errors and network errors. After that, the batch is dropped and reported.
Maximum time Close waits for queued logs to be sent, so an unreachable endpoint doesn't hold up shutdown.
Called with every delivery failure and dropped batch. By default, prints one line to stderr.
Better Stack maintains the library at github.com/BetterStackHQ/slog-betterstack since version 1.4.4. The API and the shape of the logs are unchanged.
github.com/BetterStackHQ/slog-betterstack and run go get.defer handler.Close() so the logs still queued are sent before your program exits.Please reach out to us at hello@betterstack.com.
We're happy to help! π
We use cookies to authenticate users, improve the product user experience, and for personalized ads. Learn more.