go-bugfixes
Logging helpers and router-agnostic net/http middleware for Go 1.26+. Panics caught by the middleware and errors logged through the library are reported to BugFixes.
Install
go get github.com/bugfixes/go-bugfixesConfigure
Create an agent in the dashboard and set its key and secret:
BUGFIXES_AGENT_KEY=your-key
BUGFIXES_AGENT_SECRET=your-secret
# optional
BUGFIXES_LOCAL_ONLY=true # keep reporting local
BUGFIXES_LOG_LEVEL=warn # minimum level sent remotelyLogging
package main
import "github.com/bugfixes/go-bugfixes/logs"
func main() {
logger := logs.Local()
_ = logger.Infof("server started on %s", ":8080")
_ = logs.Warn("cache is warming")
}Middleware
The default chain adds logging, request IDs, panic recovery and lower-cased headers.
package main
import (
"net/http"
bugfixes "github.com/bugfixes/go-bugfixes/middleware"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
})
handler := bugfixes.DefaultMiddleware(mux)
if err := http.ListenAndServe(":8080", handler); err != nil {
panic(err)
}
}Or build the chain yourself, including CORS and security headers:
system := bugfixes.NewMiddleware()
system.AddAllowedOrigins("https://example.com")
system.SetSecure(true)
system.AddMiddleware(
bugfixes.Logger,
bugfixes.RequestID,
bugfixes.Recoverer,
system.CORS,
system.Secure,
)
handler := system.Handler(mux)