{"id":15446195,"url":"https://github.com/moul/zapring","last_synced_at":"2025-04-14T19:12:11.830Z","repository":{"id":38013337,"uuid":"348804005","full_name":"moul/zapring","owner":"moul","description":"💍 In-memory RING buffer backend for the Zap logger","archived":false,"fork":false,"pushed_at":"2025-03-24T18:37:36.000Z","size":72,"stargazers_count":6,"open_issues_count":15,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T19:11:59.982Z","etag":null,"topics":["golang","in-memory","logger","logging","ring-buffer","zap"],"latest_commit_sha":null,"homepage":"https://manfred.life/golang","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE-APACHE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["moul"],"patreon":"moul","open_collective":"moul","custom":["https://manfred.life/donate"]}},"created_at":"2021-03-17T17:58:37.000Z","updated_at":"2023-12-13T22:05:30.000Z","dependencies_parsed_at":"2023-12-06T17:29:24.836Z","dependency_job_id":"957c9d9c-f38c-4d2f-8faf-427436435f4a","html_url":"https://github.com/moul/zapring","commit_stats":{"total_commits":28,"total_committers":4,"mean_commits":7.0,"dds":0.4642857142857143,"last_synced_commit":"e7492dbd199042496a16cd6bf7ada0c930d730d0"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":"moul/golang-repo-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moul%2Fzapring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moul%2Fzapring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moul%2Fzapring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moul%2Fzapring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moul","download_url":"https://codeload.github.com/moul/zapring/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248943458,"owners_count":21186958,"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","in-memory","logger","logging","ring-buffer","zap"],"created_at":"2024-10-01T19:59:45.170Z","updated_at":"2025-04-14T19:12:11.758Z","avatar_url":"https://github.com/moul.png","language":"Go","funding_links":["https://github.com/sponsors/moul","https://patreon.com/moul","https://opencollective.com/moul","https://manfred.life/donate"],"categories":[],"sub_categories":[],"readme":"# zapring\n\n:smile: zapring\n\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white)](https://pkg.go.dev/moul.io/zapring)\n[![License](https://img.shields.io/badge/license-Apache--2.0%20%2F%20MIT-%2397ca00.svg)](https://github.com/moul/zapring/blob/master/COPYRIGHT)\n[![GitHub release](https://img.shields.io/github/release/moul/zapring.svg)](https://github.com/moul/zapring/releases)\n[![Docker Metrics](https://images.microbadger.com/badges/image/moul/zapring.svg)](https://microbadger.com/images/moul/zapring)\n[![Made by Manfred Touron](https://img.shields.io/badge/made%20by-Manfred%20Touron-blue.svg?style=flat)](https://manfred.life/)\n\n[![Go](https://github.com/moul/zapring/workflows/Go/badge.svg)](https://github.com/moul/zapring/actions?query=workflow%3AGo)\n[![Release](https://github.com/moul/zapring/workflows/Release/badge.svg)](https://github.com/moul/zapring/actions?query=workflow%3ARelease)\n[![PR](https://github.com/moul/zapring/workflows/PR/badge.svg)](https://github.com/moul/zapring/actions?query=workflow%3APR)\n[![GolangCI](https://golangci.com/badges/github.com/moul/zapring.svg)](https://golangci.com/r/github.com/moul/zapring)\n[![codecov](https://codecov.io/gh/moul/zapring/branch/master/graph/badge.svg)](https://codecov.io/gh/moul/zapring)\n[![Go Report Card](https://goreportcard.com/badge/moul.io/zapring)](https://goreportcard.com/report/moul.io/zapring)\n[![CodeFactor](https://www.codefactor.io/repository/github/moul/zapring/badge)](https://www.codefactor.io/repository/github/moul/zapring)\n\n[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/moul/zapring)\n\n## Usage\n\n[embedmd]:# (example_test.go /import\\ / $)\n```go\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"io\"\n\t\"io/ioutil\"\n\n\t\"go.uber.org/zap\"\n\t\"go.uber.org/zap/zapcore\"\n\t\"moul.io/zapring\"\n)\n\nfunc Example_custom() {\n\tencoderConfig := zap.NewDevelopmentEncoderConfig()\n\tencoderConfig.TimeKey = \"\" // used to make this test consistent (not depending on current timestamp)\n\tencoder := zapcore.NewJSONEncoder(encoderConfig)\n\tlevel := zap.LevelEnablerFunc(func(_ zapcore.Level) bool { return true })\n\tring := zapring.New(uint(10 * 1024 * 1024)) // 10Mb ring\n\tdefer ring.Close()\n\tcore := ring.\n\t\tSetNextCore(zapcore.NewCore(encoder, zapcore.AddSync(ioutil.Discard), level)).\n\t\tSetEncoder(encoder)\n\tlogger := zap.New(\n\t\tcore,\n\t\tzap.Development(),\n\t\tzap.AddCaller(),\n\t)\n\tdefer logger.Sync()\n\tlogger.Info(\"hello world!\")\n\tlogger.Info(\"lorem ipsum\")\n\n\tr, w := io.Pipe()\n\tgo func() {\n\t\t_, err := ring.WriteTo(w)\n\t\tif err != nil \u0026\u0026 err != io.EOF {\n\t\t\tpanic(err)\n\t\t}\n\t\tw.Close()\n\t}()\n\tscanner := bufio.NewScanner(r)\n\tlines := 0\n\tfor scanner.Scan() {\n\t\tfmt.Println(\"--\u003e \", scanner.Text())\n\t\tlines++\n\t\tif lines == 2 {\n\t\t\tbreak\n\t\t}\n\t}\n\n\t// Output:\n\t// --\u003e  {\"L\":\"INFO\",\"C\":\"zapring/example_test.go:30\",\"M\":\"hello world!\"}\n\t// --\u003e  {\"L\":\"INFO\",\"C\":\"zapring/example_test.go:31\",\"M\":\"lorem ipsum\"}\n}\n\nfunc Example_composite() {\n\tcli := zap.NewExample()\n\tcli.Info(\"hello cli!\")\n\tring := zapring.New(10 * 1024 * 1024) // 10MB ring-buffer\n\tencoderConfig := zap.NewDevelopmentEncoderConfig()\n\tencoderConfig.TimeKey = \"\" // used to make this test consistent (not depending on current timestamp)\n\tring.SetEncoder(zapcore.NewJSONEncoder(encoderConfig))\n\t// FIXME: ring.Info(\"hello ring!\")\n\tcomposite := zap.New(\n\t\tzapcore.NewTee(cli.Core(), ring),\n\t\tzap.Development(),\n\t)\n\tcomposite.Info(\"hello composite!\")\n\n\tr, w := io.Pipe()\n\tgo func() {\n\t\t_, err := ring.WriteTo(w)\n\t\tif err != nil \u0026\u0026 err != io.EOF {\n\t\t\tpanic(err)\n\t\t}\n\t\tw.Close()\n\t}()\n\tcomposite.Info(\"hello composite 2!\")\n\tcli.Info(\"hello cli 2!\")\n\tcomposite.With(zap.String(\"foo\", \"bar\")).Warn(\"warn composite!\")\n\tscanner := bufio.NewScanner(r)\n\tlines := 0\n\tfor scanner.Scan() {\n\t\tfmt.Println(\"-\u003e \", scanner.Text())\n\t\tlines++\n\t\tif lines == 3 {\n\t\t\tbreak\n\t\t}\n\t}\n\n\t// Output:\n\t// {\"level\":\"info\",\"msg\":\"hello cli!\"}\n\t// {\"level\":\"info\",\"msg\":\"hello composite!\"}\n\t// {\"level\":\"info\",\"msg\":\"hello composite 2!\"}\n\t// {\"level\":\"info\",\"msg\":\"hello cli 2!\"}\n\t// {\"level\":\"warn\",\"msg\":\"warn composite!\",\"foo\":\"bar\"}\n\t// -\u003e  {\"L\":\"INFO\",\"M\":\"hello composite!\"}\n\t// -\u003e  {\"L\":\"INFO\",\"M\":\"hello composite 2!\"}\n\t// -\u003e  {\"L\":\"WARN\",\"M\":\"warn composite!\",\"foo\":\"bar\"}\n}\n\nfunc Example_simple() {\n\tring := zapring.New(10 * 1024 * 1024) // 10MB ring-buffer\n\tlogger := zap.New(ring, zap.Development())\n\tlogger.Info(\"test\")\n\t// Output:\n}\n```\n\n[embedmd]:# (.tmp/usage.txt txt /TYPES/ $)\n```txt\nTYPES\n\ntype Core struct {\n\tzapcore.Core\n\n\t// Has unexported fields.\n}\n    Core is an in-memory ring buffer log that implements zapcore.Core.\n\nfunc New(size uint) *Core\n    New returns a ring-buffer with a capacity of 'size' bytes.\n\nfunc (c *Core) Check(entry zapcore.Entry, checked *zapcore.CheckedEntry) *zapcore.CheckedEntry\n    Check implements zapcore.Core.\n\nfunc (c *Core) Close()\n    Close implements zapcore.Core.\n\nfunc (c *Core) Enabled(level zapcore.Level) bool\n    Enabled implements zapcore.LevelEnabler.\n\nfunc (c *Core) SetEncoder(enc zapcore.Encoder) *Core\n\nfunc (c *Core) SetNextCore(core zapcore.Core) *Core\n\nfunc (c *Core) Sync() error\n    Sync implements zapcore.Core.\n\nfunc (c *Core) With(fields []zapcore.Field) zapcore.Core\n    With implements zapcore.Core.\n\nfunc (c *Core) Write(entry zapcore.Entry, fields []zapcore.Field) error\n    Write implements zapcore.Core.\n\nfunc (c *Core) WriteTo(w io.Writer) (n int64, err error)\n    WriteTo implements io.WriterTo.\n\n```\n\n## Install\n\n### Using go\n\n```sh\ngo get moul.io/zapring\n```\n\n### Releases\n\nSee https://github.com/moul/zapring/releases\n\n## Contribute\n\n![Contribute \u003c3](https://raw.githubusercontent.com/moul/moul/master/contribute.gif)\n\nI really welcome contributions.\nYour input is the most precious material.\nI'm well aware of that and I thank you in advance.\nEveryone is encouraged to look at what they can do on their own scale;\nno effort is too small.\n\nEverything on contribution is sum up here: [CONTRIBUTING.md](./CONTRIBUTING.md)\n\n### Contributors ✨\n\n\u003c!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --\u003e\n[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg)](#contributors)\n\u003c!-- ALL-CONTRIBUTORS-BADGE:END --\u003e\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://manfred.life\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/94029?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eManfred Touron\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#maintenance-moul\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e \u003ca href=\"https://github.com/moul/zapring/commits?author=moul\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"https://github.com/moul/zapring/commits?author=moul\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/moul/zapring/commits?author=moul\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://manfred.life/moul-bot\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/41326314?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003emoul-bot\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#maintenance-moul-bot\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors)\nspecification. Contributions of any kind welcome!\n\n### Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/moul/zapring.svg)](https://starchart.cc/moul/zapring)\n\n## License\n\n© 2021   [Manfred Touron](https://manfred.life)\n\nLicensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)\n([`LICENSE-APACHE`](LICENSE-APACHE)) or the [MIT license](https://opensource.org/licenses/MIT)\n([`LICENSE-MIT`](LICENSE-MIT)), at your option.\nSee the [`COPYRIGHT`](COPYRIGHT) file for more details.\n\n`SPDX-License-Identifier: (Apache-2.0 OR MIT)`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoul%2Fzapring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoul%2Fzapring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoul%2Fzapring/lists"}