{"id":37179211,"url":"https://github.com/stratastor/logger","last_synced_at":"2026-01-14T20:51:59.144Z","repository":{"id":268350260,"uuid":"904023138","full_name":"stratastor/logger","owner":"stratastor","description":"A Minimal Go Package for Structured JSON Logging with Optional Sentry Integration. Easily configurable and concurrency-safe, it supports method chaining and independent logger instances.","archived":false,"fork":false,"pushed_at":"2024-12-16T07:36:59.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-12-29T07:26:33.493Z","etag":null,"topics":["golang-logger","logging","sentry-logger","stratastor","structured-logging"],"latest_commit_sha":null,"homepage":"","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/stratastor.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-12-16T05:25:33.000Z","updated_at":"2024-12-21T06:02:19.000Z","dependencies_parsed_at":"2024-12-16T08:34:15.426Z","dependency_job_id":"d5a03000-50ca-41ed-a474-8489bf30f850","html_url":"https://github.com/stratastor/logger","commit_stats":null,"previous_names":["stratastor/logger"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stratastor/logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratastor%2Flogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratastor%2Flogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratastor%2Flogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratastor%2Flogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stratastor","download_url":"https://codeload.github.com/stratastor/logger/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stratastor%2Flogger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28434500,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["golang-logger","logging","sentry-logger","stratastor","structured-logging"],"created_at":"2026-01-14T20:51:58.311Z","updated_at":"2026-01-14T20:51:59.118Z","avatar_url":"https://github.com/stratastor.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Logger Package\n\n## Overview\n\nThis package provides a structured JSON logging solution that wraps `log/slog` and optionally integrates with Sentry for error tracking and monitoring. The package is designed for convenience and flexibility, allowing developers to easily configure and use the logger with minimal boilerplate.\n\n## Features\n\n- Structured JSON logging using `log/slog`.\n- Optional integration with Sentry for error tracking.\n- Simple configuration using a `Config` struct.\n- Method chaining for convenient logging.\n- Instance-Specific Configuration: Each logger instance is initialized with its own Config struct, which includes the Sentry configuration. This ensures that each instance operates independently.\n- Concurrency Safety: Since there is no shared mutable state, the logger instances can be used concurrently without risking race conditions.\n\n## Installation\n\nTo install the package, use:\n\n```sh\ngo get github.com/stratastor/logger\n```\n\n## Usage\n\n### Basic Usage\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \"github.com/stratastor/logger\"\n)\n\nfunc main() {\n    config := logger.Config{\n        LogLevel:    \"info\",\n        SentryDSN:   \"\",\n        EnableSentry: false,\n    }\n\n    l, err := logger.New(config)\n    if err != nil {\n        log.Fatalf(\"Failed to initialize logger: %v\", err)\n    }\n\n    l.Info(\"This is an info message\")\n}\n```\n\n### Using Tags\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \"github.com/stratastor/logger\"\n)\n\nfunc main() {\n    config := logger.Config{\n        LogLevel:    \"info\",\n        SentryDSN:   \"\",\n        EnableSentry: false,\n    }\n\n    l, err := logger.NewTag(config, \"example\")\n    if err != nil {\n        log.Fatalf(\"Failed to initialize logger: %v\", err)\n    }\n\n    l.Info(\"This is an info message with a tag\")\n}\n```\n\n### Enabling Sentry\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \"github.com/stratastor/logger\"\n)\n\nfunc main() {\n    config := logger.Config{\n        LogLevel:    \"error\",\n        SentryDSN:   \"your-sentry-dsn\",\n        EnableSentry: true,\n    }\n\n    l, err := logger.New(config)\n    if err != nil {\n        log.Fatalf(\"Failed to initialize logger: %v\", err)\n    }\n\n    l.Error(\"This is an error message\")\n}\n```\n\n### Concurency safe usage\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \"sync\"\n\n    \"github.com/stratastor/logger\"\n)\n\nfunc main() {\n    config1 := logger.Config{\n        LogLevel:    \"info\",\n        SentryDSN:   \"dsn1\",\n        EnableSentry: true,\n    }\n\n    config2 := logger.Config{\n        LogLevel:    \"debug\",\n        SentryDSN:   \"\",\n        EnableSentry: false,\n    }\n\n    var wg sync.WaitGroup\n    wg.Add(2)\n\n    go func() {\n        defer wg.Done()\n        log1, err := logger.NewTag(config1, \"tag1\")\n        if err != nil {\n            log.Fatalf(\"Failed to initialize logger1: %v\", err)\n        }\n        log1.Info(\"This is an info message from logger1\")\n    }()\n\n    go func() {\n        defer wg.Done()\n        log2, err := logger.NewTag(config2, \"tag2\")\n        if err != nil {\n            log.Fatalf(\"Failed to initialize logger2: %v\", err)\n        }\n        log2.Debug(\"This is a debug message from logger2\")\n    }()\n\n    wg.Wait()\n}\n```\n\n## Design Decisions\n\n### Direct Alias for `*slog.Logger`\n\nThe package uses `type Logger = *slog.Logger` to directly alias `*slog.Logger`. This decision was made to:\n\n- Simplify the codebase by avoiding the need to wrap all methods of `slog.Logger`.\n- Allow method chaining directly on the Logger instance.\n- Provide convenience and flexibility for developers.\n\n### Configuration Struct\n\nA `Config` struct is used to encapsulate configuration options such as log level, Sentry DSN, and whether to enable Sentry. This approach makes the logger easy to configure and extend in the future.\n\n### Sentry Integration\n\nThe package provides optional integration with Sentry for error tracking. If Sentry is enabled and configured, log messages with a level of `warn` or higher are sent to Sentry. This integration helps in monitoring and tracking errors in production environments.\n\n\n### Concurency Safetey\n\nBy managing the Sentry state within the Logger instance or configuration and avoiding global state, the logger package is concurrency-safe. Each logger instance is configured independently, ensuring that concurrent usage does not lead to race conditions or inconsistent behavior.\n\n## Conclusion\n\nThis logger package provides a convenient and flexible solution for structured JSON logging with optional Sentry integration. By leveraging `log/slog` and providing a simple configuration interface, the package aims to make logging easy and effective for developers.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstratastor%2Flogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstratastor%2Flogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstratastor%2Flogger/lists"}