{"id":32596012,"url":"https://github.com/gkats/httplog","last_synced_at":"2026-07-03T09:02:12.420Z","repository":{"id":57494280,"uuid":"96114794","full_name":"gkats/httplog","owner":"gkats","description":"Simple logger for HTTP requests https://godoc.org/github.com/gkats/httplog","archived":false,"fork":false,"pushed_at":"2017-07-09T08:56:30.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-30T04:56:36.092Z","etag":null,"topics":["golang","golang-package","http","logging"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gkats.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-03T13:38:50.000Z","updated_at":"2017-07-11T10:31:16.000Z","dependencies_parsed_at":"2022-09-02T06:22:00.510Z","dependency_job_id":null,"html_url":"https://github.com/gkats/httplog","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gkats/httplog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkats%2Fhttplog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkats%2Fhttplog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkats%2Fhttplog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkats%2Fhttplog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gkats","download_url":"https://codeload.github.com/gkats/httplog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkats%2Fhttplog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35079379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-03T02:00:05.635Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","golang-package","http","logging"],"created_at":"2025-10-30T04:56:14.903Z","updated_at":"2026-07-03T09:02:12.408Z","avatar_url":"https://github.com/gkats.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gkats/httplog\n\nPackage `httplog` provides logging for http requests.\n\nApart from a ready to use logger that can be used freely, the package also provides a logging middleware (or wrapper) over http Handlers.\n\n## Install\n\n```\n$ go get github.com/gkats/httplog\n```\n\n## Details\n\nThe functionality is purposely kept minimal. The logger outputs a small set of default parameters and provides an extensible way to log extra parameters if needed. The log format is a nice balance between human and machine readability.\n\nThe log output is one line per request. The parameters are separated with a blank space while the parameter key and its value are separated by the \"=\" character. Here's an example log output for a single request.\n```\nlevel=I time=2017-07-08T17:08:12UTC ip=193.92.20.19 method=GET path=/logs ua=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36 status=200 params={}\n```\n\n## Default log parameters\n\nThis is a complete list of the default parameters that are logged.\n\nName | Description\n-----|-------------\n__level__ | The log output level. This will always be set to (I)nfo. There's really no need for any other log levels.\n__time__ | The timestamp of the log entry. The date follows the [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format (YYYY-MM-DDTHH:mm:ssZ)\n__ip__ | The request's IP. Takes into account the `X-Forwarded-For` header if it's set.\n__method__ | The request method.\n__path__ | The path for the request, leaving out the hostname part.\n__ua__ | The request's `User-Agent` header.\n__status__ | The response status code.\n__params__ | Any parameters that came with the request. The parameters will be logged in JSON format, even for non-JSON requests. The parameters are taken from either the request body or the query parameters (for GET requests).\n\n## Usage\n\n### Standalone\n\nThe logger needs a stream that implements the [io.Writer](https://golang.org/pkg/io/#Writer) interface. This is where all logging output will go.\n```\ntype stream struct {}\n\nfunc (s *stream) Write(p []byte) (n int, err error) {\n  // write somewhere\n}\n\nl := httplog.New(\u0026stream{})\nl.Log()\n```\n\n### Middleware\n\nIf you're familiar with the `http.Handler` middleware pattern, you just need to provide your handler and a logger as arguments to the `httplog.WithLogging` function.\n```\ntype customHandler {}\n\nfunc (h *customHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {\n  w.WriteHeader(200)\n  // ...your handler logic goes here...\n}\n\nfunc main() {\n  // Configure a logger\n  l := httplog.New(os.Stdout)\n\n  // And use the middleware\n  http.Handle(\"/logs\", httplog.WithLogging(\u0026customHandler{}, l))\n  http.ListenAndServe(\":8080\", nil)\n}\n```\n\nPerforming a request to `GET http://server.url:8080/logs?q=works` will produce the following line in your server's standard output.\n```\nlevel=I time=2017-07-08T17:08:12UTC ip=193.92.20.19 method=GET path=/logs ua=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36 status=200 params={\"q\": \"works\"}\n```\n\n### Adding extra log parameters\n\nSometimes you might want to log some extra parameters, like information about the user making requests. You can use the logger's `Add` method and specify the parameter name and the value.\n```\ntype User struct {\n  ID int\n}\nuser := \u0026User{ID: 1234}\n\nl := httplog.New(os.Stdout)\nl.Add(\"uid\", user.ID)\nl.Add(\"meta\", \"new-request\")\nl.Log()\n\n// =\u003e level=I [...] uid=1234 meta=new-request\n```\n\n## Contributing\n\nPull requests, bug fixes and issue reports are more than welcome! Please keep in mind that the goal is to keep the functionality minimal.\n\n## License\n\nThe package is released under the [MIT License](https://opensource.org/licenses/MIT)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkats%2Fhttplog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgkats%2Fhttplog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkats%2Fhttplog/lists"}