httplog
httplog copied to clipboard
Logged request URLs contain duplicate host/port (e.g., "http://example.comhttp://example.com/api")
Problem:
When using httplog with structured logging (e.g., SchemaGCP), the requestUrl field in logs incorrectly duplicates the host and port:
{
"httpRequest": {
"requestUrl": "http://localhost:8080http://localhost:8080/api/users", // ❌ Duplicated
"requestMethod": "GET",
"requestPath": "/api/users"
}
}
Expected:
{
"httpRequest": {
"requestUrl": "http://localhost:8080/api/users", // ✅ Correct
"requestMethod": "GET",
"requestPath": "/api/users"
}
}
How to Reproduce:
var requestLogger = httplog.RequestLogger(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelInfo,
})), &httplog.Options{
Level: slog.LevelInfo,
RecoverPanics: true,
Schema: httplog.SchemaGCP,
})
- Use the logger middleware in your application.
- Make a request to any endpoint.
- Check the logs: The
requestUrlfield will show the host/port twice.