{"id":21424352,"url":"https://github.com/gomodules/nats-logr","last_synced_at":"2025-06-15T12:05:40.261Z","repository":{"id":35227366,"uuid":"193877085","full_name":"gomodules/nats-logr","owner":"gomodules","description":"A https://github.com/go-logr/logr implementation using https://nats.io","archived":false,"fork":false,"pushed_at":"2023-03-04T21:48:43.000Z","size":34,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-30T02:54:58.823Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gomodules.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":"2019-06-26T09:50:36.000Z","updated_at":"2024-06-19T20:05:21.187Z","dependencies_parsed_at":"2024-06-19T20:05:18.922Z","dependency_job_id":"fdb241cd-efd4-48b7-ba97-3e799594aa84","html_url":"https://github.com/gomodules/nats-logr","commit_stats":{"total_commits":7,"total_committers":3,"mean_commits":"2.3333333333333335","dds":0.4285714285714286,"last_synced_commit":"bfbb9c6450c94991130afc902296a475dc02a0be"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/gomodules/nats-logr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gomodules%2Fnats-logr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gomodules%2Fnats-logr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gomodules%2Fnats-logr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gomodules%2Fnats-logr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gomodules","download_url":"https://codeload.github.com/gomodules/nats-logr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gomodules%2Fnats-logr/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259971330,"owners_count":22940009,"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":[],"created_at":"2024-11-22T21:21:21.162Z","updated_at":"2025-06-15T12:05:40.242Z","avatar_url":"https://github.com/gomodules.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nats-logr\nA [logr](https://github.com/go-logr/logr) implementation using https://nats.io\n\nUsage\n---\n\n### Code Example\n\n\n### Description\n\nTo use [nats-logr](https://github.com/gomodules/nats-logr), you have to do the following:\n\n- Run the following in a window:\n\t```$ nats-streaming-server --cluster_id=example-cluster```\n- Run the following `.go` file in second window:\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n\t\"os/signal\"\n\t\"time\"\n\n\t\"github.com/nats-io/stan.go\"\n)\n\nfunc processMsg(msg *stan.Msg) {\n\tfmt.Printf(\"Received on [%s]: '%s'\\n\", msg.Subject, msg)\n\tmsg.Ack()\n}\n\nfunc logCloser(c io.Closer) {\n\tif err := c.Close(); err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"Close error: %v\", err)\n\t\tos.Exit(1)\n\t}\n}\n\nfunc main() {\n\tconn, err := stan.Connect(\n\t\t\"example-cluster\",\n\t\t\"example-client-2\",\n\t\tstan.NatsURL(stan.DefaultNatsURL),\n\t\tstan.SetConnectionLostHandler(func(_ stan.Conn, reason error) {\n\t\t\tfmt.Fprintf(os.Stderr, \"Connection lost, reason: \", reason)\n\t\t\tos.Exit(1)\n\t\t}),\n\t)\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"Can't connect: %v.\\nMake sure a NATS Streaming Server is running at: %s\", err, stan.DefaultNatsURL)\n\t\tos.Exit(1)\n\t}\n\tdefer logCloser(conn)\n\n\tfmt.Printf(\"Connected to %s clusterID: [%s] clientID: [%s]\\n\", stan.DefaultNatsURL, \"example-cluster\", \"example-client-2\")\n\n\tsub, err := conn.QueueSubscribe(\n\t\t\"nats-log-example\",\n\t\t\"test\", func(msg *stan.Msg) {\n\t\t\tprocessMsg(msg)\n\t\t}, stan.SetManualAckMode(), stan.DurableName(\"i-remember\"), stan.DeliverAllAvailable(), stan.AckWait(time.Second),\n\t)\n\tdefer logCloser(sub)\n\t\n\tch := make(chan os.Signal, 1)\n\tsignal.Notify(ch, os.Interrupt)\n\t\u003c-ch\n}\n\n```\n- Finally, run the following code in another window: \n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"flag\"\n\t\"fmt\"\n\n\tnatslogr \"gomodules.xyz/nats-logr\"\n\n\t\"github.com/nats-io/stan.go\"\n)\n\nfunc main() {\n\tflag.Set(\"v\", \"4\")\n\tflag.Parse()\n\n\tnatslogr.InitFlags(nil)\n\tdefer natslogr.Flush()\n\n\topts := natslogr.Options{\n\t\tClusterID: \"example-cluster\",\n\t\tClientID:  \"example-client\",\n\t\tSubject:   \"nats-log-example\",\n\t}\n\tlogger := natslogr.NewLogger(opts).\n\t\tWithName(\"Example\").\n\t\tWithValues(\"withKey\", \"withValue\")\n\tlogger.Info(\"Log Example\", \"key\", \"value\")\n\n\tlogger.V(0).Info(\"Another Log Example\", \"logr\", \"nats-logr\")\n\n\tlogger.Error(errors.New(\"an error has been occured\"), \"error msg\", \"logr\", \"nats-logr\")\n}\n\n```\n\nNow, you will see the logs in the second window.\n\n## Acknowledgement\nThe logger parts of this library has been adapted from [k8s.io/klog](https://github.com/kubernetes/klog) which itself is a fork of [golang/glog](https://github.com/golang/glog).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgomodules%2Fnats-logr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgomodules%2Fnats-logr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgomodules%2Fnats-logr/lists"}