{"id":25228292,"url":"https://github.com/n-r-w/ctxlog","last_synced_at":"2025-08-25T01:17:36.306Z","repository":{"id":274168247,"uuid":"922119118","full_name":"n-r-w/ctxlog","owner":"n-r-w","description":"Context-aware structured logging for Go that wraps log/slog with Zap backend, providing enhanced performance and configuration options","archived":false,"fork":false,"pushed_at":"2025-05-15T19:27:16.000Z","size":65,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-15T20:29:31.971Z","etag":null,"topics":["context","logging","slog","zap"],"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/n-r-w.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-25T11:18:37.000Z","updated_at":"2025-05-15T19:26:58.000Z","dependencies_parsed_at":"2025-04-05T13:41:39.107Z","dependency_job_id":"31f7218a-1861-4e89-992e-13f78b73f7ae","html_url":"https://github.com/n-r-w/ctxlog","commit_stats":null,"previous_names":["n-r-w/ctxlog"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/n-r-w/ctxlog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n-r-w%2Fctxlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n-r-w%2Fctxlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n-r-w%2Fctxlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n-r-w%2Fctxlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/n-r-w","download_url":"https://codeload.github.com/n-r-w/ctxlog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n-r-w%2Fctxlog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271989992,"owners_count":24854701,"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","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"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":["context","logging","slog","zap"],"created_at":"2025-02-11T09:57:21.836Z","updated_at":"2025-08-25T01:17:36.301Z","avatar_url":"https://github.com/n-r-w.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CTXLog\n\nA context-aware structured logging package for Go that provides a robust wrapper around `log/slog` with enhanced functionality and configuration options. Under the hood, it uses `go.uber.org/zap` as the logging backend for optimal performance and reliability.\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/n-r-w/ctxlog.svg)](https://pkg.go.dev/github.com/n-r-w/ctxlog)\n![CI Status](https://github.com/n-r-w/ctxlog/actions/workflows/go.yml/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/n-r-w/ctxlog)](https://goreportcard.com/report/github.com/n-r-w/ctxlog)\n\n## Package Overview\n\nCTXLog is designed to simplify structured logging in Go applications by providing context-aware logging capabilities with support for both development and production environments. It seamlessly integrates with Go's standard `log/slog` package while adding powerful features like context propagation, sampling, and OpenTelemetry integration. The package leverages `go.uber.org/zap` as its logging backend, combining the convenience of `slog`'s interface with Zap's high-performance logging capabilities.\n\n## Key Features\n\n- Context-aware logging with automatic context propagation\n- Support for both development (human-readable) and production (JSON) logging formats\n- Automatic source code location (file and line number) tracking\n- Log sampling capabilities for high-throughput applications\n- OpenTelemetry integration\n- Built-in test logging support\n- Error logging with automatic stack traces\n- Convenient helper functions for common logging patterns\n- Group-based logging for better organization\n- High-performance logging through Zap backend\n\n## Configuration Options\n\nThe logger can be configured using the following options:\n\n### Environment Mode\n\n- `WithEnvType()`: Sets the logger environment mode\n  - `EnvDevelopment`: Human-readable logs for development\n  - `EnvProduction`: JSON logs for production (default)\n\n### Log Level and Source\n\n- `WithLevel(level slog.Leveler)`: Sets the minimum logging level\n- `WithSource(bool)`: Adds file name and line number to log records\n\n### Identification\n\n- `WithName(name string)`: Sets the logger name\n\n### Sampling\n\n- `WithSampler(tick time.Duration, first, thereafter int)`: Configures log sampling\n  - `tick`: Sampling interval\n  - `first`: Number of entries to log during the interval\n  - `thereafter`: Number of entries to log after the initial entries\n\n### Integration\n\n- `WithOtelTracing()`: Enables OpenTelemetry integration\n- `WithTesting(t testing.TB)`: Configures logger for use in tests\n\n## Installation\n\n```bash\ngo get github.com/n-r-w/ctxlog\n```\n\n## Usage Examples\n\nSee [example/main.go](example/main.go) for comprehensive usage examples, including:\n\n- Basic logger setup with production mode and debug level\n- Context propagation and extraction\n- Structured logging with various field types\n- Group-based logging\n- Error handling with automatic stack traces\n- Working with context-bound loggers\n\nThe example demonstrates all major features and provides a practical reference for integrating CTXLog into your application.\n\n## ILogger Interface\n\nILogger is a logger interface to extract the logger implementation from the project to external dependencies.\n\nThis package contains two implementations of the ctxlog.ILogger interface:\n\n- ctxlog.NewWrapper - allows wrapping ctxlog.Logger in this interface.\n- ctxlog.NewStubWrapper - fake logging. It does not do anything.\n\n## Golang Migrate Support\n\nCTXLog provides integration with [golang-migrate/migrate](https://github.com/golang-migrate/migrate) through the `GolangMigrateLogger` adapter. This allows you to use ctxlog as the logging backend for database migrations.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn-r-w%2Fctxlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fn-r-w%2Fctxlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn-r-w%2Fctxlog/lists"}