{"id":19772163,"url":"https://github.com/zerodha/logf","last_synced_at":"2025-04-30T17:33:17.777Z","repository":{"id":40411348,"uuid":"507491999","full_name":"zerodha/logf","owner":"zerodha","description":"Extremely fast, light weight, zero alloc logfmt logging library for Go.","archived":false,"fork":false,"pushed_at":"2022-09-16T05:54:19.000Z","size":266,"stargazers_count":94,"open_issues_count":1,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-24T07:52:30.093Z","etag":null,"topics":["golang-logger","golang-logging","log","logfmt","logger","logging","logging-library"],"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/zerodha.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}},"created_at":"2022-06-26T06:07:37.000Z","updated_at":"2025-03-21T20:41:12.000Z","dependencies_parsed_at":"2022-07-14T05:50:29.940Z","dependency_job_id":null,"html_url":"https://github.com/zerodha/logf","commit_stats":null,"previous_names":["mr-karan/logf"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerodha%2Flogf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerodha%2Flogf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerodha%2Flogf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zerodha%2Flogf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zerodha","download_url":"https://codeload.github.com/zerodha/logf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251751388,"owners_count":21637914,"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","golang-logging","log","logfmt","logger","logging","logging-library"],"created_at":"2024-11-12T05:05:38.072Z","updated_at":"2025-04-30T17:33:17.504Z","avatar_url":"https://github.com/zerodha.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca href=\"https://zerodha.tech\"\u003e\u003cimg src=\"https://zerodha.tech/static/images/github-badge.svg\" align=\"right\" /\u003e\u003c/a\u003e\n\n# 💥 logf\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/zerodha/logf.svg)](https://pkg.go.dev/github.com/zerodha/logf)\n[![Go Report Card](https://goreportcard.com/badge/zerodha/logf)](https://goreportcard.com/report/zerodha/logf)\n[![GitHub Actions](https://github.com/zerodha/logf/actions/workflows/build.yml/badge.svg)](https://github.com/zerodha/logf/actions/workflows/build.yml)\n\n`logf` is a high-performance, zero-alloc logging library for Go applications with a minimal API overhead. It's also the fastest logfmt logging library for Go.\n\n`logf` emits structured logs in [`logfmt`](https://brandur.org/logfmt) style. `logfmt` is a flexible format that involves `key=value` pairs to emit structured log lines. `logfmt` achieves the goal of generating logs that are not just machine-friendly but also readable by humans, unlike the clunky JSON lines.\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"time\"\n\n\t\"github.com/zerodha/logf\"\n)\n\nfunc main() {\n\tlogger := logf.New(logf.Opts{\n\t\tEnableColor:          true,\n\t\tLevel:                logf.DebugLevel,\n\t\tCallerSkipFrameCount: 3,\n\t\tEnableCaller:         true,\n\t\tTimestampFormat:      time.RFC3339Nano,\n\t\tDefaultFields:        []any{\"scope\", \"example\"},\n\t})\n\n\t// Basic logs.\n\tlogger.Info(\"starting app\")\n\tlogger.Debug(\"meant for debugging app\")\n\n\t// Add extra keys to the log.\n\tlogger.Info(\"logging with some extra metadata\", \"component\", \"api\", \"user\", \"karan\")\n\n\t// Log with error key.\n\tlogger.Error(\"error fetching details\", \"error\", \"this is a dummy error\")\n\n\t// Log the error and set exit code as 1.\n\tlogger.Fatal(\"goodbye world\")\n}\n```\n\n### Text Output\n\n```bash\ntimestamp=2022-07-07T12:09:10.221+05:30 level=info message=\"starting app\"\ntimestamp=2022-07-07T12:09:10.221+05:30 level=info message=\"logging with some extra metadata\" component=api user=karan\ntimestamp=2022-07-07T12:09:10.221+05:30 level=error message=\"error fetching details\" error=\"this is a dummy error\"\ntimestamp=2022-07-07T12:09:10.221+05:30 level=fatal message=\"goodbye world\"\n```\n\n### Console Output\n\n![](examples/screenshot.png)\n\n## Why another lib\n\nThere are several logging libraries, but the available options didn't meet our use case.\n\n`logf` meets our constraints of:\n\n- Clean API\n- Minimal dependencies\n- Structured logging but human-readable (`logfmt`!)\n- Sane defaults out of the box\n\n## Benchmarks\n\nYou can run benchmarks with `make bench`.\n\n### No Colors (Default)\n\n```\nBenchmarkNoField-8                       7884771               144.2 ns/op             0 B/op          0 allocs/op\nBenchmarkOneField-8                      6251565               186.7 ns/op             0 B/op          0 allocs/op\nBenchmarkThreeFields-8                   6273717               188.2 ns/op             0 B/op          0 allocs/op\nBenchmarkErrorField-8                    6687260               174.8 ns/op             0 B/op          0 allocs/op\nBenchmarkHugePayload-8                   3395139               360.3 ns/op             0 B/op          0 allocs/op\nBenchmarkThreeFields_WithCaller-8        2764860               437.9 ns/op           216 B/op          2 allocs/op\n```\n\n### With Colors\n\n```\nBenchmarkNoField_WithColor-8             6501867               186.6 ns/op             0 B/op          0 allocs/op\nBenchmarkOneField_WithColor-8            5938155               205.7 ns/op             0 B/op          0 allocs/op\nBenchmarkThreeFields_WithColor-8         4613145               379.4 ns/op             0 B/op          0 allocs/op\nBenchmarkErrorField_WithColor-8          3512522               353.6 ns/op             0 B/op          0 allocs/op\nBenchmarkHugePayload_WithColor-8         1520659               799.5 ns/op             0 B/op          0 allocs/op\n```\n\nFor a comparison with existing popular libs, visit [uber-go/zap#performance](https://github.com/uber-go/zap#performance).\n\n## LICENSE\n\n[LICENSE](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzerodha%2Flogf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzerodha%2Flogf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzerodha%2Flogf/lists"}