{"id":13830246,"url":"https://github.com/go-simpler/sloglint","last_synced_at":"2025-12-29T23:28:48.738Z","repository":{"id":194418151,"uuid":"690790894","full_name":"go-simpler/sloglint","owner":"go-simpler","description":"🪵 Ensure consistent code style when using log/slog","archived":false,"fork":false,"pushed_at":"2025-06-09T00:53:34.000Z","size":105,"stargazers_count":201,"open_issues_count":5,"forks_count":9,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-06-30T02:06:19.595Z","etag":null,"topics":["go","linter","logging","slog","static-analysis","tool"],"latest_commit_sha":null,"homepage":"https://go-simpler.org/sloglint","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/go-simpler.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-09-12T22:16:50.000Z","updated_at":"2025-06-15T18:58:01.000Z","dependencies_parsed_at":"2023-09-13T08:03:26.494Z","dependency_job_id":"e173897b-4210-407c-a978-9e6d024bc448","html_url":"https://github.com/go-simpler/sloglint","commit_stats":null,"previous_names":["tmzane/sloglint","go-simpler/sloglint"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/go-simpler/sloglint","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-simpler%2Fsloglint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-simpler%2Fsloglint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-simpler%2Fsloglint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-simpler%2Fsloglint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-simpler","download_url":"https://codeload.github.com/go-simpler/sloglint/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-simpler%2Fsloglint/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264450556,"owners_count":23610194,"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","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","linter","logging","slog","static-analysis","tool"],"created_at":"2024-08-04T10:00:57.780Z","updated_at":"2025-12-29T23:28:48.695Z","avatar_url":"https://github.com/go-simpler.png","language":"Go","funding_links":[],"categories":["General"],"sub_categories":[],"readme":"# sloglint\n\n[![checks](https://github.com/go-simpler/sloglint/actions/workflows/checks.yml/badge.svg)](https://github.com/go-simpler/sloglint/actions/workflows/checks.yml)\n[![pkg.go.dev](https://pkg.go.dev/badge/go-simpler.org/sloglint.svg)](https://pkg.go.dev/go-simpler.org/sloglint)\n[![goreportcard](https://goreportcard.com/badge/go-simpler.org/sloglint)](https://goreportcard.com/report/go-simpler.org/sloglint)\n[![codecov](https://codecov.io/gh/go-simpler/sloglint/branch/main/graph/badge.svg)](https://codecov.io/gh/go-simpler/sloglint)\n\nA Go linter that ensures consistent code style when using `log/slog`.\n\n## 📌 About\n\nThe `log/slog` API allows two different types of arguments: key-value pairs and attributes.\nWhile people may have different opinions about which one is better, most seem to agree on one thing: it should be consistent.\nWith `sloglint` you can enforce various rules for `log/slog` based on your preferred code style.\n\n## 🚀 Features\n\n* Enforce not mixing key-value pairs and attributes (default)\n* Enforce using either key-value pairs only or attributes only (optional)\n* Enforce not using global loggers (optional)\n* Enforce using methods that accept a context (optional)\n* Enforce using static messages (optional)\n* Enforce message style (optional)\n* Enforce using constants instead of raw keys (optional)\n* Enforce key naming convention (optional)\n* Enforce not using specific keys (optional)\n* Enforce putting arguments on separate lines (optional)\n\n## 📦 Install\n\n`sloglint` is integrated into [`golangci-lint`][1], and this is the recommended way to use it.\n\nTo enable the linter, add the following lines to `.golangci.yml`:\n\n```yaml\nlinters:\n  enable:\n    - sloglint\n```\n\nAlternatively, you can download a prebuilt binary from the [Releases][2] page to use `sloglint` standalone.\n\n## 📋 Usage\n\nRun `golangci-lint` with `sloglint` enabled.\nSee the list of [available options][3] to configure the linter.\n\nWhen using `sloglint` standalone, pass the options as flags of the same name.\n\n### No mixed arguments\n\nThe `no-mixed-args` option causes `sloglint` to report mixing key-values pairs and attributes within a single function call:\n\n```go\nslog.Info(\"a user has logged in\", \"user_id\", 42, slog.String(\"ip_address\", \"192.0.2.0\")) // sloglint: key-value pairs and attributes should not be mixed\n```\n\nIt is enabled by default.\n\n### Key-value pairs only\n\nThe `kv-only` option causes `sloglint` to report any use of attributes:\n\n```go\nslog.Info(\"a user has logged in\", slog.Int(\"user_id\", 42)) // sloglint: attributes should not be used\n```\n\n### Attributes only\n\nIn contrast, the `attr-only` option causes `sloglint` to report any use of key-value pairs:\n\n```go\nslog.Info(\"a user has logged in\", \"user_id\", 42) // sloglint: key-value pairs should not be used\n```\n\n### No global\n\nSome projects prefer to pass loggers as explicit dependencies.\nThe `no-global` option causes `sloglint` to report the use of global loggers.\n\n```go\nslog.Info(\"a user has logged in\", \"user_id\", 42) // sloglint: global logger should not be used\n```\n\nPossible values are `all` (report all global loggers) and `default` (report only the default `slog` logger).\n\n### Context only\n\nSome `slog.Handler` implementations make use of the given `context.Context` (e.g. to access context values).\nFor them to work properly, you need to pass a context to all logger calls.\nThe `context-only` option causes `sloglint` to report the use of methods without a context:\n\n```go\nslog.Info(\"a user has logged in\") // sloglint: InfoContext should be used instead\n```\n\nPossible values are `all` (report all contextless calls) and `scope` (report only if a context exists in the scope of the outermost function).\n\n### Static messages\n\nTo get the most out of structured logging, you may want to require log messages to be static.\nThe `static-msg` option causes `sloglint` to report non-static messages:\n\n```go\nslog.Info(fmt.Sprintf(\"a user with id %d has logged in\", 42)) // sloglint: message should be a string literal or a constant\n```\n\nThe report can be fixed by moving dynamic values to arguments:\n\n```go\nslog.Info(\"a user has logged in\", \"user_id\", 42)\n```\n\n### Message style\n\nThe `msg-style` option causes `sloglint` to check log messages for a particular style.\n\nPossible values are `lowercased` (report messages that begin with an uppercase letter)...\n\n```go\nslog.Info(\"Msg\") // sloglint: message should be lowercased\n```\n\n...and `capitalized` (report messages that begin with a lowercase letter):\n\n```go\nslog.Info(\"msg\") // sloglint: message should be capitalized\n```\n\nSpecial cases such as acronyms (e.g. `HTTP`, `U.S.`) are ignored.\n\n### No raw keys\n\nTo prevent typos, you may want to forbid the use of raw keys altogether.\nThe `no-raw-keys` option causes `sloglint` to report the use of strings as keys\n(including `slog.Attr` calls, e.g. `slog.Int(\"user_id\", 42)`):\n\n```go\nslog.Info(\"a user has logged in\", \"user_id\", 42) // sloglint: raw keys should not be used\n```\n\nThis report can be fixed by using either constants...\n\n```go\nconst UserId = \"user_id\"\n\nslog.Info(\"a user has logged in\", UserId, 42)\n```\n\n...or custom `slog.Attr` constructors:\n\n```go\nfunc UserId(value int) slog.Attr { return slog.Int(\"user_id\", value) }\n\nslog.Info(\"a user has logged in\", UserId(42))\n```\n\n\u003e [!TIP]\n\u003e Such helpers can be automatically generated for you by the [`sloggen`][4] tool. Give it a try too!\n\n### Key naming convention\n\nTo ensure consistency in logs, you may want to enforce a single key naming convention.\nThe `key-naming-case` option causes `sloglint` to report keys written in a case other than the given one:\n\n```go\nslog.Info(\"a user has logged in\", \"user-id\", 42) // sloglint: keys should be written in snake_case\n```\n\nPossible values are `snake`, `kebab`, `camel`, or `pascal`.\n\n### Forbidden keys\n\nTo prevent accidental use of reserved log keys, you may want to forbid specific keys altogether.\nThe `forbidden-keys` option causes `sloglint` to report the use of forbidden keys:\n\n```go\nslog.Info(\"a user has logged in\", \"reserved\", 42) // sloglint: \"reserved\" key is forbidden and should not be used\n```\n\nFor example, when using the standard `slog.JSONHandler` and `slog.TextHandler`,\nyou may want to forbid the `time`, `level`, `msg`, and `source` keys, as these are used by the handlers.\n\n### Arguments on separate lines\n\nTo improve code readability, you may want to put arguments on separate lines, especially when using key-value pairs.\nThe `args-on-sep-lines` option causes `sloglint` to report 2+ arguments on the same line:\n\n```go\nslog.Info(\"a user has logged in\", \"user_id\", 42, \"ip_address\", \"192.0.2.0\") // sloglint: arguments should be put on separate lines\n```\n\nThis report can be fixed by reformatting the code:\n\n```go\nslog.Info(\"a user has logged in\",\n    \"user_id\", 42,\n    \"ip_address\", \"192.0.2.0\",\n)\n```\n\n[1]: https://golangci-lint.run\n[2]: https://github.com/go-simpler/sloglint/releases\n[3]: https://golangci-lint.run/usage/linters/#sloglint\n[4]: https://github.com/go-simpler/sloggen\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-simpler%2Fsloglint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-simpler%2Fsloglint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-simpler%2Fsloglint/lists"}