Go library to log http.Client's requests and responses automatically
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
global
.gitignore
.travis.yml
LICENSE
README.md
loghttp.go
loghttp_go16.go
loghttp_test.go

README.md

go-loghttp

Log http.Client's requests and responses automatically.

GoDoc

Synopsis

To log all the HTTP requests/responses, import github.com/motemen/go-loghttp/global.

package main

import (
	"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/
<!doctype html>
...

Or set loghttp.Transport to http.Client's Transport field.

import "github.com/motemen/go-loghttp"

client := &http.Client{
	Transport: &loghttp.Transport{},
}

You can modify loghttp.Transport's LogRequest and LogResponse to customize logging function.

Author

motemen motemen@gmail.com