{"id":23124970,"url":"https://github.com/matusollah/slogcolor","last_synced_at":"2025-08-08T15:51:24.210Z","repository":{"id":223035336,"uuid":"759147922","full_name":"MatusOllah/slogcolor","owner":"MatusOllah","description":"Color handler for log/slog","archived":false,"fork":false,"pushed_at":"2025-07-29T14:14:15.000Z","size":68,"stargazers_count":21,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-29T17:03:54.256Z","etag":null,"topics":["ansi-colors","color","go","go-slog","golang","golang-slog","golang-slog-handler","log","logger","logging","slog","structured-logging","zerolog"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/MatusOllah/slogcolor","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/MatusOllah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2024-02-17T19:24:14.000Z","updated_at":"2025-07-24T16:24:57.000Z","dependencies_parsed_at":"2024-05-11T20:28:34.699Z","dependency_job_id":"afd3009b-4b33-47c6-8e8a-4102a64faf39","html_url":"https://github.com/MatusOllah/slogcolor","commit_stats":null,"previous_names":["matusollah/slogcolor"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/MatusOllah/slogcolor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatusOllah%2Fslogcolor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatusOllah%2Fslogcolor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatusOllah%2Fslogcolor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatusOllah%2Fslogcolor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatusOllah","download_url":"https://codeload.github.com/MatusOllah/slogcolor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatusOllah%2Fslogcolor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269447898,"owners_count":24418754,"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-08T02:00:09.200Z","response_time":72,"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":["ansi-colors","color","go","go-slog","golang","golang-slog","golang-slog-handler","log","logger","logging","slog","structured-logging","zerolog"],"created_at":"2024-12-17T08:12:09.668Z","updated_at":"2025-08-08T15:51:24.191Z","avatar_url":"https://github.com/MatusOllah.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌈 slogcolor\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/MatusOllah/slogcolor.svg)](https://pkg.go.dev/github.com/MatusOllah/slogcolor) [![Go Report Card](https://goreportcard.com/badge/github.com/MatusOllah/slogcolor)](https://goreportcard.com/report/github.com/MatusOllah/slogcolor) [![Go](https://github.com/MatusOllah/slogcolor/actions/workflows/go.yml/badge.svg)](https://github.com/MatusOllah/slogcolor/actions/workflows/go.yml) [![GitHub license](https://img.shields.io/github/license/MatusOllah/slogcolor)](https://github.com/MatusOllah/slogcolor/blob/main/LICENSE) [![Made in Slovakia](https://raw.githubusercontent.com/pedromxavier/flag-badges/refs/heads/main/badges/SK.svg)](https://www.youtube.com/watch?v=UqXJ0ktrmh0)\n\n![screenshot](https://github.com/MatusOllah/slogcolor/blob/main/screenshot.png)\n\n**slogcolor** is a little, customizable color handler for `log/slog`. It enhances log readability by color-coding log levels and supports flexible formatting options.\nIts output is inspired by XMRig and zerolog.\n\n## Installation\n\nRun:\n\n```sh\ngo get -u github.com/MatusOllah/slogcolor\n```\n\n## Basic Usage\n\n```go\npackage main\n\nimport (\n    \"os\"\n    \"time\"\n    \"errors\"\n    \"log/slog\"\n\n    \"github.com/MatusOllah/slogcolor\"\n)\n\nfunc main() {\n    // Configure slog to use slogcolor by default for colored output\n    slog.SetDefault(slog.New(slogcolor.NewHandler(os.Stderr, slogcolor.DefaultOptions)))\n\n    slog.Info(\"Initializing\")\n    slog.Debug(\"Init done\", \"duration\", 500*time.Millisecond)\n    slog.Warn(\"Slow request!\", \"method\", \"GET\", \"path\", \"/api/users\", \"duration\", 750*time.Millisecond)\n    slog.Error(\"DB connection lost!\", \"err\", errors.New(\"connection reset\"), \"db\", \"horalky\")\n}\n```\n\n### Default options\n\nslogcolor provides a set of predefined options to simplify configuration. You can use these default options via [`DefaultOptions`](https://pkg.go.dev/github.com/MatusOllah/slogcolor#DefaultOptions), or simply pass `nil` for the same effect.\n\n```go\nslog.SetDefault(slog.New(slogcolor.NewHandler(os.Stderr, slogcolor.DefaultOptions)))\n\n// or\n\nslog.SetDefault(slog.New(slogcolor.NewHandler(os.Stderr, nil)))\n```\n\nThe behavior is identical in both cases, so you can choose based on your coding style or preference.\n\n### Customized output format\n\nThe output format can also be customized using the [`Options`](https://pkg.go.dev/github.com/MatusOllah/slogcolor#Options) like this:\n\n```go\nopts := \u0026slogcolor.Options{\n    Level:         slog.LevelDebug,\n    TimeFormat:    time.RFC3339,\n    SrcFileMode:   slog.Nop,\n}\nslog.SetDefault(slog.New(slogcolor.NewHandler(os.Stderr, opts)))\n```\n\nor like this:\n\n```go\nopts := slogcolor.DefaultOptions\nopts.Level = slog.LevelDebug\nopts.TimeFormat = time.RFC3339\nopts.SrcFileMode = slog.Nop\n\nslog.SetDefault(slog.New(slogcolor.NewHandler(os.Stderr, opts)))\n```\n\n### Prefixes\n\nPrefixes can be useful for adding context to log messages, such as identifying different subsystems or components (e.g., `DB`, `SceneController`, `Network`) that generated the log.\n\nMessages can be prefixed with [`Prefix`](https://pkg.go.dev/github.com/MatusOllah/slogcolor#Prefix) like this:\n\n```go\nslog.Info(slogcolor.Prefix(\"MyPrefix\", \"kajšmentke\"))\nslog.Info(slogcolor.Prefix(\"SceneController\", \"switching scene\"), \"scene\", \"MainMenuScene\")\n\n// or\n\nslog.Info(slogcolor.Prefix(\"MyPrefix\")+\"kajšmentke\")\nslog.Info(slogcolor.Prefix(\"SceneController\")+\"switching scene\", \"scene\", \"MainMenuScene\")\n```\n\nIt can also be used as an alias for ease of use, especially when you frequently use prefixes, like this:\n\n```go\nvar P = slogcolor.Prefix\n\nslog.Info(P(\"MyPrefix\", \"kajšmentke\"))\n\n// or\n\nslog.Info(P(\"MyPrefix\")+\"kajšmentke\")\n```\n\n### Disable colors\n\nColors are enabled by default but can be disabled using `Options.NoColor`. Particularly useful for automatically enabling colors based on the terminal capabilities using e.g. the [go-isatty](https://github.com/mattn/go-isatty) package.\n\n```go\nw := os.Stderr\n\nopts := slogcolor.DefaultOptions\nopts.NoColor = !isatty.IsTerminal(w.Fd())\n\nslog.SetDefault(slog.New(slogcolor.NewHandler(w, opts)))\n```\n\n## License\n\nLicensed under the **MIT License** (see [LICENSE](https://github.com/MatusOllah/slogcolor/blob/main/LICENSE))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatusollah%2Fslogcolor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatusollah%2Fslogcolor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatusollah%2Fslogcolor/lists"}