{"id":24010815,"url":"https://github.com/mickamy/slogger","last_synced_at":"2026-06-12T18:31:36.153Z","repository":{"id":270940220,"uuid":"911910446","full_name":"mickamy/slogger","owner":"mickamy","description":"Slogger: A Friendly Wrapper for Go's slog Package","archived":false,"fork":false,"pushed_at":"2025-05-27T00:25:52.000Z","size":21,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-27T01:24:54.797Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mickamy.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":"2025-01-04T06:53:56.000Z","updated_at":"2025-05-27T00:25:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"c66f684a-6a3c-4379-8bb0-eed91bdbe5db","html_url":"https://github.com/mickamy/slogger","commit_stats":null,"previous_names":["mickamy/slogger"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/mickamy/slogger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mickamy%2Fslogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mickamy%2Fslogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mickamy%2Fslogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mickamy%2Fslogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mickamy","download_url":"https://codeload.github.com/mickamy/slogger/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mickamy%2Fslogger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34258365,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"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":[],"created_at":"2025-01-08T04:16:21.809Z","updated_at":"2026-06-12T18:31:36.133Z","avatar_url":"https://github.com/mickamy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `slogger`\n\n`slogger` is a lightweight wrapper for Go's standard logging library [slog](https://pkg.go.dev/log/slog). It simplifies logging with an intuitive API, enhanced context support, and flexible configuration options.\n\n---\n\n## Features\n\n- **Simplified API**  \n  Log messages with concise and intuitive function calls.\n- **Context Support**  \n  Add custom fields to logs using `context.Context`.\n- **Source Information**  \n  Automatically appends the file name and line number to each log message.\n- **Flexible Configuration**  \n  Customize log levels, output destinations, path trimming, and additional context fields.\n- **Standard Logger Compatibility**  \n  Fully compatible with `log.Logger` for seamless integration with existing libraries.\n\n---\n\n## Installation\n\nInstall the library using:\n\n```bash\ngo get github.com/mickamy/slogger\n```\n\n---\n\n## Usage\n\n### Initialization\n\nBefore using `slogger`, initialize it with a configuration.\n\n```go\npackage main\n\nimport (\n    \"context\"\n\t\"github.com/mickamy/slogger\"\n)\n\nfunc main() {\n\t// Initialize slogger\n\tslogger.Init(slogger.Config{\n\t\tLevel:          slogger.LevelInfo,\n\t\tTrimPathPrefix: \"/path/to/the/project/\",\n\t\tContextFieldsExtractor: func(ctx context.Context) []any {\n\t\t\treturn []any{\"userID\", ctx.Value(\"userID\")}\n\t\t},\n\t})\n\n\t// Log a message\n\tslogger.Info(\"Application started\")\n}\n```\n\n---\n\n### Logging Levels\n\n`slogger` supports multiple logging levels.\n\n```go\nslogger.Debug(\"This is a debug message\")\nslogger.Info(\"This is an info message\")\nslogger.Warn(\"This is a warning message\")\nslogger.Error(\"This is an error message\")\n```\n\n---\n\n### Context-Aware Logging\n\nAdd custom fields to your logs using `context.Context`.\n\n```go\nctx := context.WithValue(context.Background(), \"userID\", 12345)\nslogger.InfoCtx(ctx, \"User logged in\")\n```\n\nExample output:\n\n```json\n{\n  \"level\": \"INFO\",\n  \"msg\": \"User logged in\",\n  \"source\": \"main.go:42\",\n  \"userID\": 12345\n}\n```\n\n---\n\n### Using as a Standard Logger\n\nYou can use `slogger` as a `log.Logger` for compatibility with other existing libraries.\n\n```go \nstdLogger := slogger.StandardLogger(slogger.LevelInfo)\nstdLogger.Println(\"This is a standard log message\")\n```\n---\n\n## Configuration Options\n\nYou can customize `slogger` by providing a Config struct during initialization.\n\n| Field                    | Description                                                              | Default                  |\n|--------------------------|--------------------------------------------------------------------------|--------------------------|\n| `Level`                  | Minimum log level (`LevelDebug`, `LevelInfo`, `LevelWarn`, `LevelError`) | `LevelInfo`              |\n| `Outputs`                | Log output destinations (`io.Writer`)                                    | `[]io.Writer{os.Stdout}` |\n| `TrimPathPrefix`         | Prefix to trim from file paths in log output                             | Empty string             |\n| `ContextFieldsExtractor` | Function to extract additional fields from `context.Context`             | `nil` (none)             |\n\n---\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmickamy%2Fslogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmickamy%2Fslogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmickamy%2Fslogger/lists"}