https://github.com/izumin5210/gentleman-logger
Simplest logging plugin for gentleman HTTP client
https://github.com/izumin5210/gentleman-logger
gentleman golang http-client logger-middleware
Last synced: 6 months ago
JSON representation
Simplest logging plugin for gentleman HTTP client
- Host: GitHub
- URL: https://github.com/izumin5210/gentleman-logger
- Owner: izumin5210
- License: mit
- Created: 2017-08-28T00:47:13.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-28T11:03:23.000Z (about 8 years ago)
- Last Synced: 2025-02-02T03:43:33.651Z (8 months ago)
- Topics: gentleman, golang, http-client, logger-middleware
- Language: Go
- Homepage: https://github.com/izumin5210/gentleman-logger
- Size: 14.6 KB
- Stars: 3
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gentleman-logger
[](https://travis-ci.org/izumin5210/gentleman-logger)
[](./LICENSE)
[](https://goreportcard.com/report/github.com/izumin5210/gentleman-logger)
[](https://godoc.org/github.com/izumin5210/gentleman-logger)## Example
```go
func main() {
// Create a new client
cli := gentleman.New()// Register logger plugin
cli.Use(logger.New(os.Stdout))// Perform the request
resp, err := cli.Request().URL("http://example.com").Send()
if err != nil {
fmt.Printf("Request error: %s\n", err)
return
}
if !res.Ok {
fmt.Printf("Invalid server response: %d\n", res.StatusCode)
return
}fmt.Printf("Status: %d\n", res.StatusCode)
fmt.Printf("Body: %s", res.String())
}
```It will output logs like below:
```
[http] --> 2017/08/25 23:35:56 GET /
Host: example.com
User-Agent: gentleman/2.0.0[http] <-- 2017/08/25 23:35:56 HTTP/2.0 200 OK (93ms)
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json; charset=utf-8
Date: Sat, 25 Aug 2017 23:35:56 GMT
Server: nginx...
```