{"id":13564585,"url":"https://github.com/sagikazarmark/slog-shim","last_synced_at":"2025-03-15T12:30:35.498Z","repository":{"id":193863606,"uuid":"689635747","full_name":"sagikazarmark/slog-shim","owner":"sagikazarmark","description":"Backward-compatible shim for log/slog","archived":true,"fork":false,"pushed_at":"2024-10-15T07:05:02.000Z","size":68,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-06T18:52:47.837Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sagikazarmark.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-10T12:46:59.000Z","updated_at":"2024-10-15T07:05:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"8ea497e0-bcbb-48d7-90ee-21dae3c5c85f","html_url":"https://github.com/sagikazarmark/slog-shim","commit_stats":null,"previous_names":["sagikazarmark/slog-shim"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagikazarmark%2Fslog-shim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagikazarmark%2Fslog-shim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagikazarmark%2Fslog-shim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagikazarmark%2Fslog-shim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sagikazarmark","download_url":"https://codeload.github.com/sagikazarmark/slog-shim/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243730895,"owners_count":20338731,"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":[],"created_at":"2024-08-01T13:01:33.255Z","updated_at":"2025-03-15T12:30:35.169Z","avatar_url":"https://github.com/sagikazarmark.png","language":"Go","funding_links":[],"categories":["Go","General"],"sub_categories":[],"readme":"\u003e [!WARNING]\n\u003e Project archived: use [slog](https://pkg.go.dev/log/slog) directly.\n\n# [slog](https://pkg.go.dev/log/slog) shim\n\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/sagikazarmark/slog-shim/ci.yaml?style=flat-square)](https://github.com/sagikazarmark/slog-shim/actions/workflows/ci.yaml)\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/mod/github.com/sagikazarmark/slog-shim)\n![Go Version](https://img.shields.io/badge/go%20version-%3E=1.20-61CFDD.svg?style=flat-square)\n[![built with nix](https://img.shields.io/badge/builtwith-nix-7d81f7?style=flat-square)](https://builtwithnix.org)\n\nGo 1.21 introduced a [new structured logging package](https://golang.org/doc/go1.21#slog), `log/slog`, to the standard library.\nAlthough it's been eagerly anticipated by many, widespread adoption isn't expected to occur immediately,\nespecially since updating to Go 1.21 is a decision that most libraries won't make overnight.\n\nBefore this package was added to the standard library, there was an _experimental_ version available at [golang.org/x/exp/slog](https://pkg.go.dev/golang.org/x/exp/slog).\nWhile it's generally advised against using experimental packages in production,\nthis one served as a sort of backport package for the last few years,\nincorporating new features before they were added to the standard library (like `slices`, `maps` or `errors`).\n\nThis package serves as a bridge, helping libraries integrate slog in a backward-compatible way without having to immediately update their Go version requirement to 1.21. On Go 1.21 (and above), it acts as a drop-in replacement for `log/slog`, while below 1.21 it falls back to `golang.org/x/exp/slog`.\n\n**How does it achieve backwards compatibility?**\n\nAlthough there's no consensus on whether dropping support for older Go versions is considered backward compatible, a majority seems to believe it is.\n(I don't have scientific proof for this, but it's based on conversations with various individuals across different channels.)\n\nThis package adheres to that interpretation of backward compatibility. On Go 1.21, the shim uses type aliases to offer the same API as `slog/log`.\nOnce a library upgrades its version requirement to Go 1.21, it should be able to discard this shim and use `log/slog` directly.\n\nFor older Go versions, the library might become unstable after removing the shim.\nHowever, since those older versions are no longer supported, the promise of backward compatibility remains intact.\n\n## Installation\n\n```shell\ngo get github.com/sagikazarmark/slog-shim\n```\n\n## Usage\n\nImport this package into your library and use it in your public API:\n\n```go\npackage mylib\n\nimport slog \"github.com/sagikazarmark/slog-shim\"\n\nfunc New(logger *slog.Logger) MyLib {\n    // ...\n}\n```\n\nWhen using the library, clients can either use `log/slog` (when on Go 1.21) or `golang.org/x/exp/slog` (below Go 1.21):\n\n```go\npackage main\n\nimport \"log/slog\"\n\n// OR\n\nimport \"golang.org/x/exp/slog\"\n\nmylib.New(slog.Default())\n```\n\n**Make sure consumers are aware that your API behaves differently on different Go versions.**\n\nOnce you bump your Go version requirement to Go 1.21, you can drop the shim entirely from your code:\n\n```diff\npackage mylib\n\n- import slog \"github.com/sagikazarmark/slog-shim\"\n+ import \"log/slog\"\n\nfunc New(logger *slog.Logger) MyLib {\n    // ...\n}\n```\n\n## License\n\nThe project is licensed under a [BSD-style license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagikazarmark%2Fslog-shim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsagikazarmark%2Fslog-shim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagikazarmark%2Fslog-shim/lists"}