{"id":13813912,"url":"https://github.com/chalvern/sugar","last_synced_at":"2026-01-11T22:00:27.364Z","repository":{"id":45435398,"uuid":"191007949","full_name":"chalvern/sugar","owner":"chalvern","description":"simpler golang logger which package sugared zap","archived":false,"fork":false,"pushed_at":"2022-08-30T11:12:36.000Z","size":15,"stargazers_count":36,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-15T01:37:14.906Z","etag":null,"topics":["go","golang","logger","sugar","zap"],"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/chalvern.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":"2019-06-09T13:10:13.000Z","updated_at":"2025-05-14T02:40:37.000Z","dependencies_parsed_at":"2022-09-02T04:21:07.964Z","dependency_job_id":null,"html_url":"https://github.com/chalvern/sugar","commit_stats":null,"previous_names":["chalvern/zlog"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/chalvern/sugar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalvern%2Fsugar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalvern%2Fsugar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalvern%2Fsugar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalvern%2Fsugar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chalvern","download_url":"https://codeload.github.com/chalvern/sugar/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chalvern%2Fsugar/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28324826,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T18:42:50.174Z","status":"ssl_error","status_checked_at":"2026-01-11T18:39:13.842Z","response_time":60,"last_error":"SSL_read: 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":["go","golang","logger","sugar","zap"],"created_at":"2024-08-04T04:01:35.835Z","updated_at":"2026-01-11T22:00:27.323Z","avatar_url":"https://github.com/chalvern.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# sugar\n\n《[中文文档](./README_zh.md)》\n\nmore simple logger which package sugared [zap](https://github.com/uber-go/zap).\nPlease learn [zap](https://github.com/uber-go/zap) first if you want advanced using.\n\n\n## something you should know\n\n* sugar use `zap.NewDevelopmentConfig()` as default config, which use console as encoding style,\n* `InitDevelopmentSugar()` set encoding being json instead of console,  which is practically better for docker's json logger plugin.\n\n\n## Leveled method\n\nall methods of zap:\n\n* Debug/Debugf\n* Info/Infof\n* Warn/Warnf\n* Error/Errorf\n* Fatal/Fatalf\n* Panic/Panicf\n\n## logs looking\nI recommend zap mostly because of its beautiful logs looking.\n\n### looking #1\nDevelopment mode with console style printing.\n\n```bash\n2019-06-10T09:13:03.672+0800    DEBUG   default/main.go:7       default development sugar of chalvern   {\"unit\": \"main\"}\n2019-06-10T09:13:03.672+0800    INFO    default/main.go:20      log of myCustomLogger info      {\"unit\": \"my_custom_logger\"}\n2019-06-10T09:13:03.672+0800    WARN    default/main.go:21      log of myCustomLogger warn      {\"unit\": \"my_custom_logger\"}\ngithub.com/chalvern/sugar.(*Logger).Warn\n        /Users/Chalvern/developer/golang/src/github.com/chalvern/sugar/logger.go:51\nmain.myCustomLogger\n        /Users/Chalvern/developer/golang/src/github.com/chalvern/sugar/examples/default/main.go:21\nmain.main\n        /Users/Chalvern/developer/golang/src/github.com/chalvern/sugar/examples/default/main.go:8\nruntime.main\n        /usr/local/go/src/runtime/proc.go:200\n2019-06-10T09:13:03.672+0800    INFO    default/main.go:26      log of myCustomLogger2 info     {\"unit\": \"my_custom_logger_2\"}\n2019-06-10T09:13:03.672+0800    WARN    default/main.go:27      log of myCustomLogger2 warn     {\"unit\": \"my_custom_logger_2\"}\ngithub.com/chalvern/sugar.(*Logger).Warn\n        /Users/Chalvern/developer/golang/src/github.com/chalvern/sugar/logger.go:51\nmain.myCustomLogger2\n        /Users/Chalvern/developer/golang/src/github.com/chalvern/sugar/examples/default/main.go:27\nmain.main\n        /Users/Chalvern/developer/golang/src/github.com/chalvern/sugar/examples/default/main.go:9\nruntime.main\n        /usr/local/go/src/runtime/proc.go:200\n```\n\n### looking #2\n\nProduction mode with json style printing (Development mode can also has json stype printing, more see [something you should know](#something-you-should-know) )\n\n```json\n{\"level\":\"info\",\"ts\":1560129183.672966,\"caller\":\"default/main.go:13\",\"msg\":\"default production sugar of chalvern\",\"unit\":\"main\"}\n{\"level\":\"info\",\"ts\":1560129183.673015,\"caller\":\"default/main.go:20\",\"msg\":\"log of myCustomLogger info\",\"unit\":\"my_custom_logger\"}\n{\"level\":\"warn\",\"ts\":1560129183.6730392,\"caller\":\"default/main.go:21\",\"msg\":\"log of myCustomLogger warn\",\"unit\":\"my_custom_logger\"}\n{\"level\":\"info\",\"ts\":1560129183.673059,\"caller\":\"default/main.go:26\",\"msg\":\"log of myCustomLogger2 info\",\"unit\":\"my_custom_logger_2\"}\n{\"level\":\"warn\",\"ts\":1560129183.673182,\"caller\":\"default/main.go:27\",\"msg\":\"log of myCustomLogger2 warn\",\"unit\":\"my_custom_logger_2\"}\n```\n\n## example\n\nyou can find example in [examples](./examples).\n\n\n### default sugar\n```go\n// cat ./examples/default/main.go\npackage main\n\nimport \"github.com/chalvern/sugar\"\n\nfunc main() {\n\n\tsugar.Debug(\"default development sugar of chalvern\")\n\tmyCustomLogger()\n\tmyCustomLogger2()\n\n\tsugar.InitProductionSugar()\n\tsugar.Debug(\"should not be printed\")\n\tsugar.Info(\"default production sugar of chalvern\")\n\tmyCustomLogger()\n\tmyCustomLogger2()\n}\n\nfunc myCustomLogger() {\n\tmyLogger := sugar.NewLoggerOf(\"my_custom_logger\")\n\tmyLogger.Info(\"log of myCustomLogger info\")\n\tmyLogger.Warn(\"log of myCustomLogger warn\")\n}\n\nfunc myCustomLogger2() {\n\tmyLogger := sugar.NewLoggerOf(\"my_custom_logger_2\")\n\tmyLogger.Info(\"log of myCustomLogger2 info\")\n\tmyLogger.Warn(\"log of myCustomLogger2 warn\")\n}\n```\n\n### custom sugar\n\n```go\npackage main\n\nimport (\n\t\"github.com/chalvern/sugar\"\n\t\"go.uber.org/zap\"\n)\n\nfunc main() {\n\tconfig := zap.NewProductionConfig()\n\tconfig.OutputPaths = []string{\"./production.log\"}\n\tconfig.ErrorOutputPaths = []string{\"./production_err.log\"}\n\tsugar.SetSugar(\u0026config)\n\n\tsugar.Info(\"main info\")\n\n\tmyCustomLogger()\n}\n\nfunc myCustomLogger() {\n\tmyLogger := sugar.NewLoggerOf(\"my_custom_logger\")\n\tmyLogger.Info(\"log of myCustomLogger info\")\n\tmyLogger.Warn(\"log of myCustomLogger warn\")\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchalvern%2Fsugar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchalvern%2Fsugar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchalvern%2Fsugar/lists"}