{"id":21035322,"url":"https://github.com/nolleh/caption_json_formatter","last_synced_at":"2025-10-14T04:32:02.315Z","repository":{"id":57517621,"uuid":"235128236","full_name":"nolleh/caption_json_formatter","owner":"nolleh","description":"Formatter for https://github.com/sirupsen/logrus. it print log human readable(colorize) logger (include pretty json), or simplest way to server log stacks(like ELK, PLG) easy to interpret ","archived":false,"fork":false,"pushed_at":"2025-04-06T03:29:16.000Z","size":501,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-29T12:58:43.719Z","etag":null,"topics":["formatter","go","golang","json","logger","logrus","logrus-fomatter","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-20T15:04:05.000Z","updated_at":"2025-07-27T17:08:19.000Z","dependencies_parsed_at":"2025-05-15T14:39:43.155Z","dependency_job_id":"ab3e73c5-4200-446f-9b58-2918d729bb97","html_url":"https://github.com/nolleh/caption_json_formatter","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/nolleh/caption_json_formatter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolleh%2Fcaption_json_formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolleh%2Fcaption_json_formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolleh%2Fcaption_json_formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolleh%2Fcaption_json_formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nolleh","download_url":"https://codeload.github.com/nolleh/caption_json_formatter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolleh%2Fcaption_json_formatter/sbom","scorecard":{"id":693515,"data":{"date":"2025-08-11","repo":{"name":"github.com/nolleh/caption_json_formatter","commit":"b4b7236ea9a06ce6de44bea946041d15de501018"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 1/29 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-22T02:55:20.281Z","repository_id":57517621,"created_at":"2025-08-22T02:55:20.281Z","updated_at":"2025-08-22T02:55:20.281Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017942,"owners_count":26086213,"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","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"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":["formatter","go","golang","json","logger","logrus","logrus-fomatter","msa"],"created_at":"2024-11-19T13:14:34.017Z","updated_at":"2025-10-14T04:32:02.297Z","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/caption_json_formatter.svg)](https://pkg.go.dev/github.com/nolleh/caption_json_formatter)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## caption-json-formatter\n\n### Feature\n\nlogrus's 'message(object)' json formatter with human-readable caption added.  \ndefault available caption is (it can be disabled)\n\n\u003e - timestamp\n\u003e - logLevel\n\nand also you can use this formatter for using simple json formatter (@since v0.2.0).\n\n### Example\n\n#### OutPut\n\n1. with custom caption (nollehLog)  \n   \u003cimg src=\"docs/images/example_01.png\" alt=\"with caption\"/\u003e\n\n2. set logger option with unpretty print (off pritty print)  \n   \u003cimg src=\"docs/images/example_02.png\" alt=\"unpretty\"/\u003e\n\n3. set logger without custom caption and set as pretty  \n   \u003cimg src=\"docs/images/example_03.png\" alt=\"no caption\"/\u003e\n\n4. use caption_json_formatter as simple json logger, to handled by other program. (like kibana, loki, whatever)\n   \u003cimg src=\"docs/images/example_04.png\" alt=\"json with default caption\"\u003e\n   it printed as\n   ```json\n   {\n     \"level\": \"info\",\n     \"message\": {\n       \"request\": { \"method\": \"GET\", \"url\": \"/user/123456/balance\" },\n       \"response\": { \"balance\": 1000, \"user\": 123456 }\n     },\n     \"time_stamp\": \"2023-03-05T18:16:47.165173+09:00\"\n   }\n   ```\n\n#### Available Options\n\n| key                      | ConsoleDefault | JsonDefault | description                                                                   |\n| ------------------------ | -------------- | ----------- | ----------------------------------------------------------------------------- |\n| TransportToJson          | false          | true        | if enabled, the whole log (include default caption) will be marshaled to json |\n| UseDefaultCaption        | true           | true        | if enabled, timestamp and loglevel will be added                              |\n| PrettyPrint              | true           | false       | if enabled, the message(object) is printed as pretty json                     |\n| CustomCaption            | nil            | nil         | if has value, then the caption is attatched before message(object)            |\n| CustomCaptionPrettyPrint | false          | false       | if enabled, the passed custom caption is printed as pretty json               |\n| Colorize                 | true           | false       | if enabled, add predefined term color code by loglevel                        |\n\n#### Source\n\n- initalization\n\n```go\n// initialize log\nvar (\n  logger = NewLogger()\n)\n\nfunc NewLogger() *logrus.Logger {\n  log.SetFlags(log.LstdFlags | log.Lshortfile)\n  log.SetOutput(os.Stdout)\n  logger := logrus.New()\n  logger.Level = logrus.TraceLevel\n  // option 1. helper function Console makes default formatter for console\n  logger.SetFormatter(caption_json_formatter.Console())\n\n  // if you want, use default constructor and modify some option.\n  // console := caption_json_formatter.Console()\n  // console.CustomCaptionPrettyPrint = true\n  // logger.SetFormatter(console)\n\n  // use JsonFormatter\n  // json := caption_json_formatter.Json()\n  // logger.SetFormatter(json)\n\n  // option 2. if you no need helper constructing, you can do yourself. (not recommended)\n  // logger.SetFormatter(\u0026caption_json_formatter.Formatter{ PrettyPrint: true })\n  return logger\n}\n\nfunc Log() *caption_json_formatter.Entry {\n\treturn \u0026caption_json_formatter.Entry{ Entry: logrus.NewEntry(logger) }\n}\n```\n\n- printLog\n\n```go\nfunc main() {\n  type Request struct {\n    Url string `json:\"url\"`\n    Method string `json:\"method\"`\n  }\n  type Response struct {\n    User int `json:\"user\"`\n    Balance int `json:\"balance\"`\n  }\n  type Message struct {\n    Request Request `json:\"request\"`\n    Response Response `json:\"response\"`\n  }\n\n  message := Message { Request{ \"/user/123456/balance\", \"GET\" }, Response{123456, 1000} }\n\n  /* in current logrus implementation, there isn't way for set Custom Entry\n  * hook or formatter, doesn't have opportunity for marshaling message.\n  * so before pull request was made, you need to use custom function to use extended entry.\n  */\n\n  Log().Debug(message)\n}\n```\n\n### When To Use\n\nit is useful when shows 'message' that include json to human.\nshow as pretty format, eventhought there is nested json. **(not strigified)**\n\nfor example, for message\n\n```go\n// accessData is json type that has request / reponse data\nlog.Debug(accessData)\n```\n\n```\n[2020-01-20T16:46:08.7452971+09:00] [Debug]\n{\n    \"request\": {\n        \"headers\": { \"content-type\": \"application/json\" },\n        \"method\": \"GET\",\n        \"route\": \"/user/{userId}/balance\",\n        \"url\": \"/user/123456/balance\"\n    },\n    \"response\": {\n        \"body\": {\n            \"userId\": 123456,\n            \"balance\": 1000\n        }\n    }\n}\n```\n\nnot like other formatters doing. (like below)\n\n```\n[2020-01-20T16:46:08.7452971+09:00] [Debug] {/\"request/\": { /\"headers/\": { /\"content-type/\": /\"application/json/\" }, /\"method/\": /\"GET/\", /\"route/\": /\"/user/{userId}/balance/\", /\"url/\": /\"/user/123456/balance/\" }, /\"response/\": { /\"body/\": { /\"userId/\": 123456, /\"balance/\": 1000 } } }\n```\n\nor\n\n```\n{ \"time\": \"2020-01-20T16:46:08.7452971+09:00\", \"msg\": {/\"request/\": { /\"headers/\": { /\"content-type/\": /\"application/json/\" }, /\"method/\": /\"GET/\", /\"route/\": /\"/user/{userId}/balance/\", /\"url/\": /\"/user/123456/balance/\" }, /\"response/\": { /\"body/\": { /\"userId/\": 123456, /\"balance/\": 1000 } }\n```\n\nor\n\n```\n\"2020-01-20T16:46:08.7452971+09:00\" {{/user/123456/balance GET} {123456 1000}}\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnolleh%2Fcaption_json_formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnolleh%2Fcaption_json_formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnolleh%2Fcaption_json_formatter/lists"}