Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 1.01 KB

README.md

File metadata and controls

56 lines (40 loc) · 1.01 KB

go-loghttp

Log http.Client's requests and responses automatically.

PkgGoDev

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