{"id":25582497,"url":"https://github.com/darvaza-proxy/slog","last_synced_at":"2025-07-01T13:07:16.225Z","repository":{"id":65163518,"uuid":"584516630","full_name":"darvaza-proxy/slog","owner":"darvaza-proxy","description":"structured logger adaptors","archived":false,"fork":false,"pushed_at":"2025-04-05T23:49:58.000Z","size":286,"stargazers_count":11,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T18:32:52.919Z","etag":null,"topics":["golang","logger","logrus","structured-logging","zap","zerolog"],"latest_commit_sha":null,"homepage":"https://darvaza.org/slog","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/darvaza-proxy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-01-02T19:44:50.000Z","updated_at":"2025-04-05T23:45:30.000Z","dependencies_parsed_at":"2024-06-20T21:50:30.907Z","dependency_job_id":"84a2e2ad-5865-489f-9f39-3da7aa0885d4","html_url":"https://github.com/darvaza-proxy/slog","commit_stats":{"total_commits":165,"total_committers":2,"mean_commits":82.5,"dds":"0.024242424242424288","last_synced_commit":"63328f2906c4025bf87eda215feb108bdd03126d"},"previous_names":[],"tags_count":203,"template":false,"template_full_name":null,"purl":"pkg:github/darvaza-proxy/slog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darvaza-proxy%2Fslog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darvaza-proxy%2Fslog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darvaza-proxy%2Fslog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darvaza-proxy%2Fslog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darvaza-proxy","download_url":"https://codeload.github.com/darvaza-proxy/slog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darvaza-proxy%2Fslog/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261391437,"owners_count":23151664,"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":["golang","logger","logrus","structured-logging","zap","zerolog"],"created_at":"2025-02-21T05:16:40.696Z","updated_at":"2025-07-01T13:07:16.190Z","avatar_url":"https://github.com/darvaza-proxy.png","language":"Go","readme":"# slog, a back-end agnostic interface for structured logs\n\n[![Go Reference][godoc-badge]][godoc]\n[![Go Report Card][goreport-badge]][goreport]\n\n[`slog.Logger`](#interface) provides a simple standardised interface for structured logs for libraries. It supports [six log levels](#log-levels) and [fields](#fields) with unique string labels (keys).\n\n[godoc]: https://pkg.go.dev/darvaza.org/slog\n[godoc-badge]: https://pkg.go.dev/badge/darvaza.org/slog.svg\n[goreport]: https://goreportcard.com/report/darvaza.org/slog\n[goreport-badge]: https://goreportcard.com/badge/darvaza.org/slog\n\n## Interface\nEvery method of this interface, with the exception of [`Print()`](#print), returns a `slog.Logger` so it can be daisy chained when composing a log entry.\nA log entry begins with setting the [level](#log-levels) followed by optional addition of [fields](#fields) and a [call stack](#call-stack) and ends with a message calling a [Print](#print) method.\nBased on the specified [level](#log-levels) an entry can be [enabled or disabled](#enabled). Calls to methods on disabled entries will cause no action unless it's used to create a new entry with a [level](#log-levels) that is enabled.\n\n## Log Levels\nAn `slog.Logger` entry can have of one of six levels, of which Fatal is expected to end the execution just like the standard `log.Fatal()`right after adding the log entry, and Panic to raise a recoverable panic like `log.Panic()`.\n\n 1. Debug\n 2. Info\n 3. Warn\n 4. Error\n 5. Fatal\n 6. Panic\n\nNew log entries can be created by calling the named shortcut methods (`Debug()`, `Info()`, `Warn()`, `Error()`, `Fatal()`, and `Panic()`) or via `WithLevel(level)`.\n\n\n## Enabled\nA log entry is considered _Enabled_ if the handler would actually log entries of the specified level.\nIt is always safe to operate on disabled loggers and the cost of should be negletable as when a logger\nis not `Enabled()` string formatting operations or fields and stack commands are not performed.\n\nSometimes it is useful to know if a certain level is *Enabled* so you can decide between two levels with different degree\nof detail. For this purpose one can use `WithEnabled()` like this:\n```go\nif log, ok := logger.Debug().WithEnabled(); ok {\n\tlog.WithField(\"request\", req).Print(\"Let's write detailed debug stuff\")\n} else if log, ok := logger.Info().WithEnabled(); ok {\n\tlog.Print(\"Let's write info stuff instead\")\n}\n```\n\nLogs of Fatal and Panic level are expected to exit/panic regardless of the _Enabled_ state.\n\n## Fields\nIn `slog` fields are unique key/value pairs where the key is a non-empty string and the value could be any type.\n\n## Call Stack\nA Call stack is attached to a log entry considering the given distance to a caller/initiator function.\n\n## Print\n`slog.Logger` support three Print methods mimicking their equivalent in the `fmt` package from the standard library. `Print()`, `Println()`, and `Printf()` that finally attempt to emit the log entry with the given message and any previously attached [Field](#fields).\n\n## Standard *log.Logger\nIn order to be compatible with the standard library's provided `log.Logger`, `slog` provides an `io.Writer` interface connected to a handler function that is expected to parse the entry and call a provided `slog.Logger` as appropriate. This _writer_ is created by calling `NewLogWriter` and passing the logger and the handler function, which is then passed to `log.New()` to create the `*log.Logger`.\n\nAlternatively a generic handler is provided when using `NewStdLogger()`.\n\n## Handlers\n\nA handler is an object that implements the `slog.Logger` interface.\nWe provide handlers to use popular loggers as _backend_.\n\n* [logrus](https://pkg.go.dev/darvaza.org/slog/handlers/logrus)\n* [zap](https://pkg.go.dev/darvaza.org/slog/handlers/zap)\n* [zerolog](https://pkg.go.dev/darvaza.org/slog/handlers/zerolog)\n\nWe also offer backend independent handlers\n\n* [cblog](https://pkg.go.dev/darvaza.org/slog/handlers/cblog), a implementation\nthat allows you to receive log entries through a channel.\n* [filter](https://pkg.go.dev/darvaza.org/slog/handlers/filter), that can filter by level and also alter log entries before passing them to another slog.Logger.\n* [discard](https://pkg.go.dev/darvaza.org/slog/handlers/discard), a placeholder that won't log anything but saves the user from checking if a logger was provided or not every time.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarvaza-proxy%2Fslog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarvaza-proxy%2Fslog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarvaza-proxy%2Fslog/lists"}