izumin5210 / gentleman-logger

Simplest logging plugin for gentleman HTTP client

Home Page:https://github.com/izumin5210/gentleman-logger

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gentleman-logger

Build Status license Go Report Card GoDoc

Example

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

<!DOCTYPE html>
...

About

Simplest logging plugin for gentleman HTTP client

https://github.com/izumin5210/gentleman-logger

License:MIT License


Languages

Language:Go 100.0%