{"id":21035326,"url":"https://github.com/nolleh/ctxlog","last_synced_at":"2026-02-16T07:32:11.973Z","repository":{"id":57697078,"uuid":"235368965","full_name":"nolleh/ctxlog","owner":"nolleh","description":"golang context logger (access logger, which print request/response per http request), and also provide middleware for echo framework (https://github.com/labstack/echo)","archived":false,"fork":false,"pushed_at":"2025-03-09T11:00:47.000Z","size":261,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-28T15:14:59.104Z","etag":null,"topics":["echo","echo-framework","go","golang","http","json","log","logrus","middleware","msa"],"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/nolleh.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-01-21T15:01:15.000Z","updated_at":"2025-03-09T11:00:11.000Z","dependencies_parsed_at":"2025-04-28T15:15:02.363Z","dependency_job_id":"cdef73f9-5b2c-45a1-a91f-17ef5d50ebc4","html_url":"https://github.com/nolleh/ctxlog","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/nolleh/ctxlog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolleh%2Fctxlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolleh%2Fctxlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolleh%2Fctxlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolleh%2Fctxlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nolleh","download_url":"https://codeload.github.com/nolleh/ctxlog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolleh%2Fctxlog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29502934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T05:57:17.024Z","status":"ssl_error","status_checked_at":"2026-02-16T05:56:49.929Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["echo","echo-framework","go","golang","http","json","log","logrus","middleware","msa"],"created_at":"2024-11-19T13:14:34.967Z","updated_at":"2026-02-16T07:32:11.958Z","avatar_url":"https://github.com/nolleh.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/nolleh/ctxlog.svg)](https://pkg.go.dev/github.com/nolleh/ctxlog)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## ctxlog\n\n---\n\necho middleware that print log for a api's request / response\n\nif you write request / response like this,\n\n\u003cimg src=\"docs/images/http_request_example.png\" alt=\"example\" width=\"800\" height=\"488\"/\u003e\n\nthen get ..\n\n\u003cimg src=\"docs/images/output.png\" alt=\"example\" width=\"600\" height=\"800\"/\u003e\n\n\u003e you need only one line to show this request/response log !\n\n`e.Use(middleware.CtxLogger())`\n\n#### more example...\n\nset formatter as warning level ctxlog\n\n\u003cimg src=\"docs/images/level_warn.png\" alt=\"warning_level_ctx_log\"/\u003e\n\nset formatter as [CaptionJsonFormatter.Json()](https://github.com/nolleh/caption_json_formatter)\n\n\u003cimg src=\"docs/images/json.png\" alt=\"json_log\"/\u003e\n\n---\n\n### configuration\n\nyou can also configuration your ctxlog.\ncolorize, json format..\ndefault ctxlog will be formatted as caption_json_formatter.Console(). see more [here](https://github.com/nolleh/caption_json_formatter)\n\nyou can change the default option, formatter, as you wish.\n\n```go\nimport (\n  cjf \"github.com/nolleh/caption_json_formatter\"\n  \"github.com/nolleh/ctxlog\"\n  \"github.com/nolleh/ctxlog/middleware\"\n)\n\nfunc main() {\n  // [optional] retreive ctxlogs formatter (CaptionJsonFormatter)\n  formatter := ctxlog.CaptionJsonFormatter()\n  // [optional] you can modify format configruation from default.\n  formatter.PrettyPrint = true\n  // [optional] or, you reset your own formatter\n  formatter = cjf.Json()\n  // [optional] and set 'ANY FORMATTER' compatiable with logrus.formatter\n  ctxlog.Logger().SetFormatter(formatter)\n\n  // Echo instance\n  e := echo.New()\n  // [required] use ctxlog middleware (if you want use middleware. or,\n  // just use ctxlog and declare your own, as you wish)\n  e.Use(middleware.CtxLogger())\n  // print level can be modified.\n  // e.Use(middleware.CtxLoggerWithLevel(logrus.WarnLevel))\n}\n```\n\n### Example Details\n\n---\n\n#### request\n\n```json\n{\n  \"name\": \"nolleh\",\n  \"say\": \"hello happy new year!\"\n}\n```\n\n#### response\n\n```json\n{\n  \"message\": \"Hello, World!\"\n}\n```\n\n#### go\n\n[example/main.go](https://github.com/nolleh/ctxlog/blob/master/example/main.go)\n\n```go\nfunc main() {\n\n    // Echo instance\n    e := echo.New()\n\n    /// this one line! (other codes are for start echo frameworks / http handler)\n    e.Use(middleware.CtxLogger())\n\n    e.POST(\"/\", hello)\n    e.Logger.Fatal(e.Start(\":1323\"))\n}\n\n// http Handler\nfunc hello(c echo.Context) error {\n\t// type Request struct {\n\t// \tName string `json:\"name\"`\n\t// \tSay string `json:\"say\"`\n\t// }\n\t// var request Request\n\t// c.Bind(\u0026request)\n\ttype Result struct {\n\t\tMessage string `json:\"message\"`\n\t}\n\n\t// and if you want to add some additional log, use it as log stream!\n\t// experience colorized, and pretty json formatting\n\t// ctxlog.Log().Info(request)\n\n\tresult := Result{\"Hello, World!\"}\n\tjson, _ := json.Marshal(result)\n\treturn c.String(http.StatusOK, string(json))\n}\n\n\n```\n\n#### Output\n\ncolored by log level\n\n```go\n// if you uncomment ctxlog.Log().Info(request), above\n2020-10-08T16:40:46.4543276+09:00 [INFO] {\n \"name\": \"nolleh\",\n \"say\": \"hello happy new year!\"\n}\n\n//\n2020-10-08T16:40:46.5171606+09:00 [TRACE] {\n \"request\": {\n  \"body\": {\n   \"name\": \"nolleh\",\n   \"say\": \"hello happy new year!\"\n  },\n  \"header\": {\n   \"Accept\": [\n    \"*/*\"\n   ],\n   \"Accept-Encoding\": [\n    \"gzip, deflate, br\"\n   ],\n   \"Cache-Control\": [\n    \"no-cache\"\n   ],\n   \"Connection\": [\n    \"keep-alive\"\n   ],\n   \"Content-Length\": [\n    \"54\"\n   ],\n   \"Content-Type\": [\n    \"application/json\"\n   ],\n   \"Postman-Token\": [\n    \"b1556c81-bf31-4e6a-8c2a-e1bd0787ebdd\"\n   ],\n   \"User-Agent\": [\n    \"PostmanRuntime/7.22.0\"\n   ]\n  },\n  \"method\": \"POST\",\n  \"uri\": \"/\"\n },\n \"requestId\": \"\",\n \"response\": {\n  \"body\": {\n   \"message\": \"Hello, World!\"\n  },\n  \"status\": 200\n }\n}\n\n```\n\n### Dependency\n\n- echo framework (for middlware implementation) [](http://github.com/labstack/echo)\n- caption_json_formatter [](http://github.com/nolleh/caption_json_formatter)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnolleh%2Fctxlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnolleh%2Fctxlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnolleh%2Fctxlog/lists"}