{"id":13830250,"url":"https://github.com/phsym/console-slog","last_synced_at":"2025-08-10T06:10:35.109Z","repository":{"id":188503692,"uuid":"678881848","full_name":"phsym/console-slog","owner":"phsym","description":"A handler for slog that prints colorized logs, similar to zerolog's console writer output without sacrificing performances","archived":false,"fork":false,"pushed_at":"2024-01-13T13:43:21.000Z","size":84,"stargazers_count":53,"open_issues_count":17,"forks_count":8,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-27T16:51:16.828Z","etag":null,"topics":["console","go","golang","log","logger","logging","slog"],"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/phsym.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}},"created_at":"2023-08-15T15:49:02.000Z","updated_at":"2025-07-25T11:20:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"221ffe8c-3f1a-468d-9f46-7e9cf3ebe447","html_url":"https://github.com/phsym/console-slog","commit_stats":null,"previous_names":["phsym/slog-console"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/phsym/console-slog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phsym%2Fconsole-slog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phsym%2Fconsole-slog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phsym%2Fconsole-slog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phsym%2Fconsole-slog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phsym","download_url":"https://codeload.github.com/phsym/console-slog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phsym%2Fconsole-slog/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269683261,"owners_count":24458644,"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-08-10T02:00:08.965Z","response_time":71,"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":["console","go","golang","log","logger","logging","slog"],"created_at":"2024-08-04T10:00:57.808Z","updated_at":"2025-08-10T06:10:35.085Z","avatar_url":"https://github.com/phsym.png","language":"Go","funding_links":[],"categories":["Go","Formatting"],"sub_categories":[],"readme":"# console-slog\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/phsym/console-slog.svg)](https://pkg.go.dev/github.com/phsym/console-slog) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/phsym/console-slog/master/LICENSE) [![Build](https://github.com/phsym/console-slog/actions/workflows/go.yml/badge.svg?branch=main)](https://github.com/phsym/slog-console/actions/workflows/go.yml) [![codecov](https://codecov.io/gh/phsym/console-slog/graph/badge.svg?token=ZIJT9L79QP)](https://codecov.io/gh/phsym/console-slog) [![Go Report Card](https://goreportcard.com/badge/github.com/phsym/console-slog)](https://goreportcard.com/report/github.com/phsym/console-slog)\n\nA handler for slog that prints colorized logs, similar to zerolog's console writer output without sacrificing performances.\n\n## Installation\n```bash\ngo get github.com/phsym/console-slog@latest\n```\n\n## Example\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"log/slog\"\n\t\"os\"\n\n\t\"github.com/phsym/console-slog\"\n)\n\nfunc main() {\n\tlogger := slog.New(\n\t\tconsole.NewHandler(os.Stderr, \u0026console.HandlerOptions{Level: slog.LevelDebug}),\n\t)\n\tslog.SetDefault(logger)\n\tslog.Info(\"Hello world!\", \"foo\", \"bar\")\n\tslog.Debug(\"Debug message\")\n\tslog.Warn(\"Warning message\")\n\tslog.Error(\"Error message\", \"err\", errors.New(\"the error\"))\n\n\tlogger = logger.With(\"foo\", \"bar\").\n\t\tWithGroup(\"the-group\").\n\t\tWith(\"bar\", \"baz\")\n\n\tlogger.Info(\"group info\", \"attr\", \"value\")\n}\n```\n\n![output](./doc/img/output.png)\n\nWhen setting `console.HandlerOptions.AddSource` to `true`:\n```go\nconsole.NewHandler(os.Stderr, \u0026console.HandlerOptions{Level: slog.LevelDebug, AddSource: true})\n```\n![output-with-source](./doc/img/output-with-source.png)\n\n## Performances\nSee [benchmark file](./bench_test.go) for details.\n\nThe handler itself performs quite well compared to std-lib's handlers. It does no allocation:\n```\ngoos: linux\ngoarch: amd64\npkg: github.com/phsym/console-slog\ncpu: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz\nBenchmarkHandlers/dummy-4               128931026            8.732 ns/op               0 B/op          0 allocs/op\nBenchmarkHandlers/console-4               849837              1294 ns/op               0 B/op          0 allocs/op\nBenchmarkHandlers/std-text-4              542583              2097 ns/op               4 B/op          2 allocs/op\nBenchmarkHandlers/std-json-4              583784              1911 ns/op             120 B/op          3 allocs/op\n```\n\nHowever, the go 1.21.0 `slog.Logger` adds some overhead:\n```\ngoos: linux\ngoarch: amd64\npkg: github.com/phsym/console-slog\ncpu: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz\nBenchmarkLoggers/dummy-4                 1239873             893.2 ns/op             128 B/op          1 allocs/op\nBenchmarkLoggers/console-4                483354              2338 ns/op             128 B/op          1 allocs/op\nBenchmarkLoggers/std-text-4               368828              3141 ns/op             132 B/op          3 allocs/op\nBenchmarkLoggers/std-json-4               393322              2909 ns/op             248 B/op          4 allocs/op\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphsym%2Fconsole-slog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphsym%2Fconsole-slog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphsym%2Fconsole-slog/lists"}