{"id":19561354,"url":"https://github.com/m-mizutani/clog","last_synced_at":"2025-07-22T16:07:06.612Z","repository":{"id":174105089,"uuid":"649164540","full_name":"m-mizutani/clog","owner":"m-mizutani","description":"Customizable Go slog Handler","archived":false,"fork":false,"pushed_at":"2025-02-01T06:34:04.000Z","size":63,"stargazers_count":26,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-14T13:35:52.417Z","etag":null,"topics":["go","golang","logging"],"latest_commit_sha":null,"homepage":"","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/m-mizutani.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}},"created_at":"2023-06-04T01:49:20.000Z","updated_at":"2025-07-07T11:56:38.000Z","dependencies_parsed_at":"2023-11-23T04:42:23.971Z","dependency_job_id":"07843c0d-d8db-4584-89b4-daa0fd8e1351","html_url":"https://github.com/m-mizutani/clog","commit_stats":null,"previous_names":["m-mizutani/clog"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/m-mizutani/clog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-mizutani%2Fclog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-mizutani%2Fclog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-mizutani%2Fclog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-mizutani%2Fclog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m-mizutani","download_url":"https://codeload.github.com/m-mizutani/clog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-mizutani%2Fclog/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266525043,"owners_count":23942864,"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-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":["go","golang","logging"],"created_at":"2024-11-11T05:11:11.788Z","updated_at":"2025-07-22T16:07:06.577Z","avatar_url":"https://github.com/m-mizutani.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# clog\n\nCustomizable slog.Handler for console.\n\n```go\npackage main\n\nimport (\n\t\"github.com/m-mizutani/clog\"\n\t\"log/slog\"\n)\n\nfunc main() {\n\thandler := clog.New(\n\t\tclog.WithColor(true),\n\t\tclog.WithSource(true),\n\t)\n\tlogger := slog.New(handler)\n\n\tlogger.Info(\"hello, world!\", slog.String(\"foo\", \"bar\"))\n\tlogger.Warn(\"What?\", slog.Group(\"group1\", slog.String(\"foo\", \"bar\")))\n\tlogger.WithGroup(\"hex\").Error(\"Ouch!\", slog.Int(\"num\", 123))\n}\n```\n\n\u003cimg width=\"997\" alt=\"Screenshot 2023-06-11 at 10 41 29\" src=\"https://github.com/m-mizutani/clog/assets/605953/2dcc46ac-2113-44e4-90d1-218bd5fcc12b\"\u003e\n\n## Options\n\n- `WithWriter`: Output writer. Default is `os.Stdout`.\n- `WithLevel`: Log level. Default is `slog.LevelInfo`.\n- `WithTimeFmt`: Time format string. Default is `15:04:05.000`.\n- `WithColor`: Enable colorized output. Default will be changed by terminal's color support.\n- `WithColorMap`: Color map for each log level. Default is `clog.DefaultColorMap`. See [ColorMap](#colormap) section for more detail.\n- `WithSource`: Enable source code location. Default is false.\n- `WithReplaceAttr`: Replace attribute value. It's same with `slog.ReplaceAttr` in `slog.HandlerOptions`.\n- `WithTemplate`: Template string. See [Template](#template) section for more detail.\n- `WithAttrPrinter`: Attribute printer. Default is `clog.LinearPrinter`. See [AttrPrinter](#attrprinter) section for more detail.\n\n### ColorMap\n\nYou can customize color map for each handler with `clog.ColorMap`. Default is `clog.DefaultColorMap`. If the fields is nil or not set, default color will be used.\n\n- `LogLevel`: You can set color for each log level. If not set, default color `LogLevelDefault` will be used.\n- `LogLevelDefault`: Default color for log level.\n- `Time`: Color for time string.\n- `Message`: Color for log message string.\n- `AttrKey`: Color for attribute key string. It's applied or not depends on AttrPrinter.\n- `AttrValue`: Color for attribute value string. It's applied or not depends on AttrPrinter.\n\n### Template\n\nTemplate can be used to customize log format. A developer can use following variables in template string.\n\n- `.Time`: Time string. Format is specified `WithTimeFmt`.\n- `.Elapsed`: Duration from the start of the program\n- `.Level`: Log level string. e.g. `INFO`, `WARN`, `ERROR`\n- `.Message`: Log message\n- `.FileName`: A file name of the source code that calls logger. It is empty if WithSource is not specified\n- `.FilePath`: A full file path of the source code that calls logger. It is empty if WithSource is not specified.\n- `.FileLine`: A line number of the source code that calls logger. It is empty if WithSource is not specified\n- `.FuncName` A function name of the source code that calls logger. It is empty if WithSource is not specified\n\nDefault is `clog.DefaultTemplate`.\n\n### AttrPrinter\n\n`AttrPrinter` is an interface designed for customizing the way attributes are printed. By default, `clog.LinearPrinter` is used.\n\n- `LinearPrinter`: Print attributes in a linear way.\n- `PrettyPrinter`: Print attributes with [pp](https://github.com/k0kubun/pp) package.\n- `IndentPrinter`: Print attributes with indent like YAML format.\n\nFull example is [here](./examples/attr_printer/main.go).\n\n```go\nfunc main() {\n\tuser := User{\n\t\tName:  \"mizutani\",\n\t\tEmail: \"mizutani@hey.com\",\n\t}\n\n\tstore := Store{\n\t\tName:    \"Jiro\",\n\t\tAddress: \"Tokyo\",\n\t\tPhone:   \"123-456-7890\",\n\t}\n\tgroup := slog.Group(\"info\", slog.Any(\"user\", user), slog.Any(\"store\", store))\n\n\tlinearHandler := clog.New(clog.WithPrinter(clog.LinearPrinter))\n\tslog.New(linearHandler).Info(\"by LinearPrinter\", group)\n\n\tprettyHandler := clog.New(clog.WithPrinter(clog.PrettyPrinter))\n\tslog.New(prettyHandler).Info(\"by PrettyPrinter\", group)\n\n\tindentHandler := clog.New(clog.WithPrinter(clog.IndentPrinter))\n\tslog.New(indentHandler).Info(\"by IndentHandler\", group)\n}\n```\n\n\u003cimg width=\"1188\" alt=\"Screenshot 2023-06-11 at 10 39 26\" src=\"https://github.com/m-mizutani/clog/assets/605953/b184644f-080b-41a9-8e5f-16a80d019311\"\u003e\n\n## License\n\nApache License 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm-mizutani%2Fclog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm-mizutani%2Fclog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm-mizutani%2Fclog/lists"}