-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable verbose Vault request logging
- Loading branch information
1 parent
be730c6
commit 2599d7e
Showing
5 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package http | ||
|
||
import ( | ||
"log/slog" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
// LoggingTransport is an http.RoundTripper that logs the request and response. | ||
type LoggingTransport struct { | ||
http.RoundTripper | ||
} | ||
|
||
// RoundTrip implements the RoundTripper interface. | ||
func (lt *LoggingTransport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
rt := lt.RoundTripper | ||
if rt == nil { | ||
rt = http.DefaultTransport | ||
} | ||
|
||
start := time.Now() | ||
|
||
resp, err := rt.RoundTrip(req) | ||
switch { | ||
case err != nil: | ||
slog.Info("HTTP error", | ||
slog.String("method", req.Method), | ||
slog.String("url", req.URL.String()), | ||
slog.Duration("duration", time.Since(start)), | ||
slog.String("error", err.Error())) | ||
case resp.StatusCode < 300: | ||
slog.Info("HTTP error response", | ||
slog.String("method", req.Method), | ||
slog.String("url", req.URL.String()), | ||
slog.Duration("duration", time.Since(start)), | ||
slog.String("status", resp.Status)) | ||
default: | ||
slog.Debug("HTTP success response", | ||
slog.String("method", req.Method), | ||
slog.String("url", req.URL.String()), | ||
slog.Duration("duration", time.Since(start)), | ||
slog.String("status", resp.Status)) | ||
} | ||
|
||
return resp, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters