{"id":47123145,"url":"https://github.com/practo/promlog","last_synced_at":"2026-03-12T19:37:42.134Z","repository":{"id":141724849,"uuid":"274088694","full_name":"practo/promlog","owner":"practo","description":"klog hook to expose Prometheus metrics. ","archived":false,"fork":false,"pushed_at":"2020-06-26T05:42:21.000Z","size":7759,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-16T07:27:40.199Z","etag":null,"topics":["golang","klog","prometheus"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/practo/promlog","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/practo.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}},"created_at":"2020-06-22T08:59:50.000Z","updated_at":"2024-03-31T15:57:32.000Z","dependencies_parsed_at":"2024-01-15T06:07:30.475Z","dependency_job_id":null,"html_url":"https://github.com/practo/promlog","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"aab7b183eca902adda6fa0bde20a8ed1dadb8118"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/practo/promlog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practo%2Fpromlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practo%2Fpromlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practo%2Fpromlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practo%2Fpromlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/practo","download_url":"https://codeload.github.com/practo/promlog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/practo%2Fpromlog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30440132,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T14:34:45.044Z","status":"ssl_error","status_checked_at":"2026-03-12T14:09:33.793Z","response_time":114,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["golang","klog","prometheus"],"created_at":"2026-03-12T19:37:41.647Z","updated_at":"2026-03-12T19:37:42.116Z","avatar_url":"https://github.com/practo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# promlog\n\n[![GoDoc Widget]][GoDoc]\n\n---\n[forked klog](https://github.com/practo/klog) hook to expose the number of log messages as Prometheus metrics:\n```\nlog_messages_total{severity=\"ERROR\"} 0\nlog_messages_total{severity=\"INFO\"} 42\nlog_messages_total{severity=\"WARNING\"} 0\n```\n\n## Usage\n\nSample code:\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/prometheus/client_golang/prometheus/promhttp\"\n\t\"github.com/practo/klog/v2\"\n\t\"github.com/practo/promlog\"\n)\n\nfunc main() {\n\t// Create the Prometheus hook:\n\thook := promlog.MustNewPrometheusHook(\"\", klog.InfoSeverityLevel)\n\n\t// Configure klog to use the Prometheus hook:\n\tklog.AddHook(hook)\n\n\t// Expose Prometheus metrics via HTTP, as you usually would:\n\tgo http.ListenAndServe(\":8080\", promhttp.Handler())\n\n\t// Log with klog, as you usually would.\n\t// Every time the program generates a log message,\n\t// a Prometheus counter is incremented for the corresponding level.\n\tfor {\n\t\tklog.Infof(\"foo\")\n\t\ttime.Sleep(1 * time.Second)\n\t}\n}\n```\n\nRun the above program:\n```\n$ cd example \u0026\u0026 go run main.go\nI0624 13:26:39.035027   51136 main.go:26] foo\nI0624 13:26:40.035543   51136 main.go:26] foo\nI0624 13:26:41.039174   51136 main.go:26] foo\nI0624 13:26:42.039930   51136 main.go:26] foo\nI0624 13:26:43.041310   51136 main.go:26] foo\n```\n\nScrape the Prometheus metrics exposed by the hook:\n```\n$ curl -fsS localhost:8080 | grep log_messages\n# HELP log_messages_total Total number of log messages.\n# TYPE log_messages_total counter\nlog_messages_total{severity=\"ERROR\"} 0\nlog_messages_total{severity=\"INFO\"} 42\nlog_messages_total{severity=\"WARNING\"} 0\n```\n\n## Compile\n```\n$ go build\n```\n\n## Test\n```\n$ go test\nI0624 13:27:29.696765   51237 promlog_test.go:49] this is at info level!\nW0624 13:27:29.697785   51237 promlog_test.go:55] this is at warning level!\nE0624 13:27:29.698964   51237 promlog_test.go:61] this is at error level!\nPASS\nok  \tgithub.com/practo/promlog\t0.237s\n```\n\n[GoDoc]: https://godoc.org/github.com/practo/promlog\n[GoDoc Widget]: https://godoc.org/github.com/practo/k8s-worker-pod-autoscaler?status.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpracto%2Fpromlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpracto%2Fpromlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpracto%2Fpromlog/lists"}