Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/motemen/go-loghttp
Go library to log http.Client's requests and responses automatically
https://github.com/motemen/go-loghttp
Last synced: 29 days ago
JSON representation
Go library to log http.Client's requests and responses automatically
- Host: GitHub
- URL: https://github.com/motemen/go-loghttp
- Owner: motemen
- License: mit
- Created: 2014-12-01T04:56:12.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-12-02T06:52:38.000Z (about 1 year ago)
- Last Synced: 2024-10-30T21:05:30.760Z (about 1 month ago)
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 118
- Watchers: 5
- Forks: 16
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ccamel - motemen/go-loghttp - Go library to log http.Client's requests and responses automatically (Go)
README
go-loghttp
==========Log http.Client's requests and responses automatically.
[PkgGoDev](https://pkg.go.dev/github.com/motemen/go-loghttp)
## Synopsis
To log all the HTTP requests/responses, import `github.com/motemen/go-loghttp/global`.
```go
package mainimport (
"io"
"log"
"net/http"
"os"_ "github.com/motemen/go-loghttp/global" // Just this line!
)func main() {
resp, err := http.Get(os.Args[1])
if err != nil {
log.Fatal(err)
}io.Copy(os.Stdout, resp.Body)
}
``````
% go run main.go http://example.com/
2014/12/02 13:36:27 ---> GET http://example.com/
2014/12/02 13:36:27 <--- 200 http://example.com/...
```Or set `loghttp.Transport` to `http.Client`'s `Transport` field.
```go
import "github.com/motemen/go-loghttp"client := &http.Client{
Transport: &loghttp.Transport{},
}
```You can modify [loghttp.Transport](http://godoc.org/github.com/motemen/go-loghttp#Transport)'s `LogRequest` and `LogResponse` to customize logging function.
## Author
motemen