{"id":15965244,"url":"https://github.com/bwplotka/go-httplog","last_synced_at":"2025-09-05T08:31:31.990Z","repository":{"id":57494314,"uuid":"88044487","full_name":"bwplotka/go-httplog","owner":"bwplotka","description":"Robust, smart logger for Golang http handlers","archived":false,"fork":false,"pushed_at":"2017-08-03T10:46:35.000Z","size":19,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-19T13:33:47.651Z","etag":null,"topics":["go","golang","http","logging","middleware","request","response"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bwplotka.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-04-12T11:30:58.000Z","updated_at":"2023-10-04T16:52:24.000Z","dependencies_parsed_at":"2022-09-06T16:21:55.574Z","dependency_job_id":null,"html_url":"https://github.com/bwplotka/go-httplog","commit_stats":null,"previous_names":["bplotka/go-httplog"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwplotka%2Fgo-httplog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwplotka%2Fgo-httplog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwplotka%2Fgo-httplog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwplotka%2Fgo-httplog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bwplotka","download_url":"https://codeload.github.com/bwplotka/go-httplog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232031973,"owners_count":18462965,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["go","golang","http","logging","middleware","request","response"],"created_at":"2024-10-07T17:40:30.496Z","updated_at":"2024-12-31T21:33:17.358Z","avatar_url":"https://github.com/bwplotka.png","language":"Go","readme":"# go-httplog\n\n[![Build Status](https://travis-ci.org/Bplotka/go-httplog.svg?branch=master)](https://travis-ci.org/Bplotka/go-httplog) [![Go Report Card](https://goreportcard.com/badge/github.com/Bplotka/go-httplog)](https://goreportcard.com/report/github.com/Bplotka/go-httplog)\n\nRobust, smart logger for Golang http request/response.\n\nIt provides way to log in details every request and response with chosen fields. It\nrequires any structured logger that fits under `httplog.FieldLogger` interface.\n\nIt comes with useful integration with [logrus](\"github.com/sirupsen/logrus\"), but it can be extend to use any logger.\nIt fits into standard `net/http` middleware (`http.Handler`) pattern, but comes also with [echo](\"github.com/labstack/echo\") integration.\n\nIt comes with bunch of configurable fields. Not exhausting list of these:\n```\nReqTimeField  = RequestField(\"req_time\")\nIDField       = RequestField(\"req_id\")\nRemoteIPField = RequestField(\"req_remote_ip\")\nHostField     = RequestField(\"req_host\")\nURIField      = RequestField(\"req_uri\")\nReqArgsField  = RequestField(\"req_args\")\nMethodField   = RequestField(\"req_method\")\nPathField     = RequestField(\"req_path\")\nBytesInField  = RequestField(\"req_bytes_in\")\nAuthField     = RequestField(\"req_auth_header\")\n\nStatusField       = ResponseField(\"res_status\")\nBytesOutField     = ResponseField(\"res_bytes_out\")\nResTimeField      = ResponseField(\"res_time\")\nContentTypeField  = ResponseField(\"res_content_type\")\nLocationField     = ResponseField(\"res_location\")\nLocationArgsField = ResponseField(\"res_location_args\")\nLocationHostField = ResponseField(\"res_location_host\")\n```\n\n## Example:\n\n```go\npackage main\n\nimport (\n    \"net/http\"\n    \n    \"github.com/Bplotka/go-httplog\"\n    \"github.com/Bplotka/go-httplog/logrus\"\n    \"github.com/sirupsen/logrus\"\n)\n\nfunc main() {\n    l := logrus.New()\n    \n    srv := http.Server{\n        Handler: httplog.RegisterMiddleware(\n            httplogrus.ToHTTPFieldLoggerDebug(l), // or ToHTTPFieldLoggerInfo if you want these logs to be in Info level.\n            httplog.DefaultReqResConfig(), // or httplog.DefaultResponseOnlyConfig() for only log line per response. \n        )(\n            http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n                // Your handler here...\n                l.Info(\"Inside!\")\n            }),\n        ),\n    }\n    \n    err := srv.Serve(...)\n    if err != nil {\n        // handle err.\n    }\n}\n```\n\nExample effect: \n\n* With `DefaultReqResConfig` on any request you will get:\n```\nDebug[0029] Received HTTP request                         req_bytes_in=0 req_host=\"127.0.0.1:\u003csome-port\u003e\" req_method=GET req_path=\"....\" req_remote_ip=127.0.0.1 req_time=\"2017-04-14T17:20:07+01:00\" \u003cany other field that will filled and configured\u003e\nInside!\nDebug[0029] Responding to HTTP request                    res_bytes_out=769 res_content_type=\"application/json\" res_status=200 res_time=\"2017-04-14T17:20:07+01:00\" \u003cany other field that will filled and configured\u003e\n```\n\nFor redirection the log can be even more useful:\n```\nDebug[0029] Received HTTP request                         req_bytes_in=0 req_host=\"127.0.0.1:\u003csome-port\u003e\" req_method=GET req_path=\"....\" req_remote_ip=127.0.0.1 req_time=\"2017-04-14T17:20:07+01:00\" \u003cany other field that will filled and configured\u003e\nInside!\nDebug[0029] Redirecting HTTP request                      res_bytes_out=0 res_location_args=\"code=...\u0026state=...\" res_location_host=\"....\" res_status=303 res_time=\"2017-04-14T17:20:07+01:00\" \u003cany other field that will filled and configured\u003e\" \n```\n\n## Integrations:\n\n### Web frameworks\n* net/http ;\u003e\n* [echo](echo/middleware.go)\n\n### Structured Loggers\n* [logrus](logrus/log.go)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwplotka%2Fgo-httplog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbwplotka%2Fgo-httplog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwplotka%2Fgo-httplog/lists"}