{"id":19962975,"url":"https://github.com/ichizero/errlog","last_synced_at":"2025-07-04T19:08:31.931Z","repository":{"id":225523673,"uuid":"766162161","full_name":"ichizero/errlog","owner":"ichizero","description":"errlog is a slog handler that logs errors with stack traces easily.","archived":false,"fork":false,"pushed_at":"2024-12-01T08:53:31.000Z","size":20,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-01T16:48:15.690Z","etag":null,"topics":["go","golang","log","slog","slog-handler"],"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/ichizero.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":"2024-03-02T14:07:12.000Z","updated_at":"2024-12-01T08:53:34.000Z","dependencies_parsed_at":"2024-03-02T17:29:15.555Z","dependency_job_id":"d9265a83-a1a0-435c-8de5-cb16bf57b5ad","html_url":"https://github.com/ichizero/errlog","commit_stats":null,"previous_names":["ichizero/errlog"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ichizero/errlog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichizero%2Ferrlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichizero%2Ferrlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichizero%2Ferrlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichizero%2Ferrlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ichizero","download_url":"https://codeload.github.com/ichizero/errlog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichizero%2Ferrlog/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263604010,"owners_count":23487223,"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","golang","log","slog","slog-handler"],"created_at":"2024-11-13T02:13:59.395Z","updated_at":"2025-07-04T19:08:31.908Z","avatar_url":"https://github.com/ichizero.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# errlog\n\n[![Test](https://github.com/ichizero/errlog/actions/workflows/test.yml/badge.svg)](https://github.com/ichizero/errlog/actions/workflows/test.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/ichizero/errlog.svg)](https://pkg.go.dev/github.com/ichizero/errlog)\n[![Codecov](https://codecov.io/gh/ichizero/errlog/branch/main/graph/badge.svg)](https://codecov.io/gh/ichizero/errlog)\n[![Go Report Card](https://goreportcard.com/badge/github.com/ichizero/errlog)](https://goreportcard.com/report/github.com/ichizero/errlog)\n\n`errlog` is a error logging package based on [log/slog](https://pkg.go.dev/log/slog) standard library.\nIt provides error logging with stack trace and source location.\nIt does not require any third-party package. \n\n## 🚀 Installation\n\n```bash\ngo get github.com/ichizero/errlog\n```\n\n## 🧐 Usage\n\n### Initialize logger\n`errlog.NewHandler` wraps `slog.Handler`, so you can provide `*slog.JSONHandler`, `*slog.TextHandler`,\nor any other handler.\n\n```go\nh := slog.NewJSONHandler(os.Stdout, \u0026slog.HandlerOptions{AddSource: true})\nhErr := errlog.NewHandler(h, \u0026errlog.HandlerOptions{OverrideSource: true, SuppressStackTrace: false})\nslog.SetDefault(slog.New(hErr))\n```\n\n### Logging error with stack trace\n\n#### With errlog.Err\n`errlog.Err` wraps error with stack trace and returns `slog.Attr` with key `error`.\n\n```go\nerr := errors.New(\"test error\")\nslog.ErrorContext(ctx, \"test\", errlog.Err(err))\n```\n\n#### With custom error\n\n`errlog.NewHandler` outputs stack trace with the error that implements `errlog.StackTrace` interface,\nso you can provide custom error with stack trace.\n\n```go\ntype yourCustomError struct {\n\terr error\n\tstack []uintptr\n}\n\nfunc (e yourCustomError) Stack() []uintptr {\n\treturn e.stack\n}\n```\n\nIf so, you can log stack trace without using `errlog.Err`.\n\n```go\nerr := newYourCustomError(\"error\")\nslog.ErrorContext(ctx, \"test\", slog.Any(\"error\", err))\n```\n\n#### Example usage\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"log/slog\"\n\t\"os\"\n\n\t\"github.com/ichizero/errlog\"\n)\n\nfunc main() {\n\th := slog.NewJSONHandler(os.Stdout, \u0026slog.HandlerOptions{AddSource: true})\n\thErr := errlog.NewHandler(h, \u0026errlog.HandlerOptions{OverrideSource: true, SuppressStackTrace: false})\n\tslog.SetDefault(slog.New(hErr))\n\n\tctx := context.Background()\n\n\terr := errors.New(\"test error\")\n\tslog.ErrorContext(ctx, \"test\", errlog.Err(err))\n\n\terr = errlog.WrapError(err)\n\tslog.ErrorContext(ctx, \"test\", slog.Any(\"error\", err))\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichizero%2Ferrlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fichizero%2Ferrlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichizero%2Ferrlog/lists"}