{"id":17961015,"url":"https://github.com/slok/noglog","last_synced_at":"2025-07-24T20:10:39.576Z","repository":{"id":52658106,"uuid":"149854977","full_name":"slok/noglog","owner":"slok","description":"\"Bring your own logger\" replacement for github.com/golang/glog.","archived":false,"fork":false,"pushed_at":"2021-04-22T01:18:02.000Z","size":41,"stargazers_count":12,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-19T08:39:26.416Z","etag":null,"topics":["glog","k8s","kubernetes","log","logger","logging","logs","replacement"],"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/slok.png","metadata":{"files":{"readme":"Readme.md","changelog":"CHANGELOG","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":"2018-09-22T07:22:12.000Z","updated_at":"2023-08-04T07:21:17.000Z","dependencies_parsed_at":"2022-09-26T17:50:54.030Z","dependency_job_id":null,"html_url":"https://github.com/slok/noglog","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slok%2Fnoglog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slok%2Fnoglog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slok%2Fnoglog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slok%2Fnoglog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slok","download_url":"https://codeload.github.com/slok/noglog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245394751,"owners_count":20608122,"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":["glog","k8s","kubernetes","log","logger","logging","logs","replacement"],"created_at":"2024-10-29T11:08:03.551Z","updated_at":"2025-03-25T03:31:31.259Z","avatar_url":"https://github.com/slok.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# noglog [![Build Status][travis-image]][travis-url] [![Go Report Card][goreport-image]][goreport-url] [![GoDoc][godoc-image]][godoc-url]\n\nnoglog is a replacement for [github.com/golang/glog][glog] implementation.\n\nThis package is a \"bring you own\" logger for glog replacement. It will replace all the glog calls with any logger that implements `noglog.Logger` interface.\n\nYou can go from this:\n\n```text\nERROR: logging before flag.Parse: I0921 14:49:49.283733       1 leaderelection.go:175] attempting to acquire leader lease example-lock...\n```\n\nto this:\n\n```text\nINFO[0000] attempting to acquire leader lease  example-lock...  source=k8s src=\"leaderelection.go:175\"\n```\n\nor whatever format you want (or don't show at all).\n\n## Features\n\n- Replace glog messages with your own logger (implement small interface and done).\n- No [flags] modification.\n\n## Getting Started\n\nFor a complete example, check [this][example]\n\n### Import library\n\nFirst we need to add noglog as dependency, but it will need to be placed on `github.com/golang/glog` import path, so `github.com/slok/noglog` code replaces `github.com/golang/glog`\n\n#### Using go modules\n\n```text\nrequire (\n    github.com/google/glog master\n)\n\nreplace (\n    github.com/google/glog =\u003e github.com/slok/noglog master\n)\n```\n\n#### Using dep\n\n```toml\n[[override]]\n  name = \"github.com/golang/glog\"\n  source = \"github.com/slok/noglog\"\n  branch = \"master\"\n```\n\n### Set our custom logger\n\nImport glog and the first thing that your app should do is instantiate your logger and set as the glog logger. Example:\n\n```golang\nimport (\n    \"github.com/golang/glog\"\n)\n\nfunc main() {\n    // Import custom logger that satisfies noglog.Logger interface.\n    logger := mylogger.New()\n\n    glog.SetLogger(logger)\n}\n```\n\nFor security reasons if you don't set a logger, it will use a dummy logger that will disable Kubernetes logs. Sometimes this is useful also.\nYour custom logger needs to satisfy `noglog.Logger` interface.\nYou have a helper if you want to create a logger using functions instead of creating a new type, `noglog.LoggerFunc`.\n\nThis helper gives a lot of power to set up loggers easily. Some examples...\n\nLogrus:\n\n```golang\nimport (\n    \"github.com/google/glog\"\n    \"github.com/sirupsen/logrus\"\n)\n\nfunc main() {\n    // Our app logger.\n    logger := logrus.New()\n    logger.SetLevel(logrus.DebugLevel)\n\n    // Set our glog replacement.\n    glog.SetLogger(\u0026glog.LoggerFunc{\n        DebugfFunc: func(f string, a ...interface{}) { logger.Debugf(f, a...) },\n        InfofFunc:  func(f string, a ...interface{}) { logger.Infof(f, a...) },\n        WarnfFunc:  func(f string, a ...interface{}) { logger.Warnf(f, a...) },\n        ErrorfFunc: func(f string, a ...interface{}) { logger.Errorf(f, a...) },\n    })\n\n    glog.Info(\"I'm batman!\")\n}\n```\n\nExample for zap:\n\n```golang\nimport (\n    \"github.com/google/glog\"\n    \"go.uber.org/zap\"\n)\n\nfunc main() {\n    // Our app logger.\n    logger, _ := zap.NewProduction()\n    slogger := logger.Sugar()\n\n    // Set our glog replacement.\n    glog.SetLogger(\u0026glog.LoggerFunc{\n        DebugfFunc: func(f string, a ...interface{}) { slogger.Debugf(f, a...) },\n        InfofFunc:  func(f string, a ...interface{}) { slogger.Infof(f, a...) },\n        WarnfFunc:  func(f string, a ...interface{}) { slogger.Warnf(f, a...) },\n        ErrorfFunc: func(f string, a ...interface{}) { slogger.Errorf(f, a...) },\n    })\n\n    glog.Info(\"I'm batman!\")\n}\n```\n\nExample for zerolog:\n\n```golang\nimport (\n    \"os\"\n\n    \"github.com/google/glog\"\n    \"github.com/rs/zerolog\"\n)\n\nfunc main() {\n    // Our app logger.\n    w := zerolog.ConsoleWriter{Out: os.Stderr}\n    logger := zerolog.New(w).With().Timestamp().Logger()\n\n    // Set our glog replacement.\n    glog.SetLogger(\u0026glog.LoggerFunc{\n        DebugfFunc: func(f string, a ...interface{}) { logger.Debug().Msgf(f, a...) },\n        InfofFunc:  func(f string, a ...interface{}) { logger.Info().Msgf(f, a...) },\n        WarnfFunc:  func(f string, a ...interface{}) { logger.Warn().Msgf(f, a...) },\n        ErrorfFunc: func(f string, a ...interface{}) { logger.Error().Msgf(f, a...) },\n    })\n\n    glog.Info(\"I'm batman!\")\n}\n```\n\n## Why\n\nGlog is a logger used on some important projects like Kubernetes, Glog modifies globals like `flag` of your program and it can't be done nothing to disable, modify...\n\nFor example in Kubernetes glog is around all the source code, they don't use a common app logger interface that it can be reimplement with any log implementation, or pass any logger as dependency injection, so the Kubernetes extensions that use [client-go] will get flags modification, unstructured logs around it well set log format lines...\n\n## When to use noglog\n\n- Tired of glog logs.\n- Every extension/app of Kubernetes I do has annoying unstructured logs.\n- My app flags have glog flags that I didn't ask for.\n- `ERROR: logging before flag.Parse: W0922` WTF when using a custom `flag.FlagSet`.\n\n## Alternatives\n\nAlthough noglog can use any logger due to the simple interface, there are other alternatives that replace the logger for a specific logger with defaults, if you don't want to bring your own or customize these loggers here are the alternatives:\n\n- [glog-logrus]\n- [istio-glog](zap)\n\n[travis-image]: https://travis-ci.org/slok/noglog.svg?branch=master\n[travis-url]: https://travis-ci.org/slok/noglog\n[goreport-image]: https://goreportcard.com/badge/github.com/slok/noglog\n[goreport-url]: https://goreportcard.com/report/github.com/slok/noglog\n[godoc-image]: https://godoc.org/github.com/slok/noglog?status.svg\n[godoc-url]: https://godoc.org/github.com/slok/noglog\n[glog]: https://github.com/golang/glog\n[client-go]: https://github.com/kubernetes/client-go\n[flags]: https://golang.org/pkg/flag\n[glog-logrus]: https://github.com/kubermatic/glog-logrus\n[istio-glog]: https://github.com/istio/glog\n[example]: /example\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslok%2Fnoglog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslok%2Fnoglog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslok%2Fnoglog/lists"}