{"id":15995874,"url":"https://github.com/mattes/log","last_synced_at":"2025-10-29T01:41:33.140Z","repository":{"id":57501722,"uuid":"220124416","full_name":"mattes/log","owner":"mattes","description":"Uber Zap logger","archived":false,"fork":false,"pushed_at":"2023-03-06T22:37:34.000Z","size":3821,"stargazers_count":4,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T05:52:16.352Z","etag":null,"topics":["go","golang","golang-logging","log","logging","zap","zap-core"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-11-07T01:25:58.000Z","updated_at":"2023-09-28T13:06:31.000Z","dependencies_parsed_at":"2024-06-20T07:15:31.686Z","dependency_job_id":"df60ca0d-bc2d-4287-bab4-85b2e56c7020","html_url":"https://github.com/mattes/log","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattes%2Flog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattes%2Flog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattes%2Flog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattes%2Flog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattes","download_url":"https://codeload.github.com/mattes/log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243891951,"owners_count":20364609,"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":["go","golang","golang-logging","log","logging","zap","zap-core"],"created_at":"2024-10-08T07:21:33.828Z","updated_at":"2025-10-29T01:41:33.068Z","avatar_url":"https://github.com/mattes.png","language":"Go","readme":"# log [![GoDoc](https://godoc.org/github.com/mattes/log?status.svg)](https://godoc.org/github.com/mattes/log)\n\nlog acts as drop-in replacement for `std/log` and uses the power of\n[Uber's Zap](https://github.com/uber-go/zap) logging library internally. \n\nIt implements the following Zap cores:\n\n  * [Google Cloud Error Reporting](/googleErrorReporting)\n  * [Google Cloud Stackdriver Logging](/googleStackdriver)\n  * [Slack](/slack)\n  * [Prometheus](/prometheus)\n\n\n## Usage\n\nA __development__ setup is used by default. Similar to `std/log`.\nAll logs are written to stderr.\n\n```go\nimport \"github.com/mattes/log\"\n\nfunc main() {\n  defer log.Sync()\n\n  log.Info(\"Hello world\")\n}\n```\n\nIn __production__ the setup depends on where you want to ship your logs to.\nHere is an example that ships all logs to Google Stackdriver, as well\nas Google Error Reporting.\n\n```go\nimport (\n  \"go.uber.org/zap\"\n  \"go.uber.org/zap/zapcore\"\n  \"github.com/mattes/log\"\n  gerr \"github.com/mattes/log/googleErrorReporting\"\n  gsdr \"github.com/mattes/log/googleStackdriver\"\n\n)\n\nfunc init() {\n  cores := []zapcore.Core{}\n\n  {\n    // Stackdriver core\n    c := gsdr.NewConfig()\n    c.LogID = \"my-service.v2\"\n    core, err := c.Build()\n    cores = append(cores, core)\n  }\n\n  {\n    // Error reporting core\n    c := gerr.NewConfig()\n    c.ServiceName = \"my-service\"\n    c.ServiceVersion = \"v2\"\n    core, err := c.Build()\n    cores = append(cores, core)\n  }\n\n  // Build Zap logger with options\n  logger := zap.New(zapcore.NewTee(cores...)).WithOptions(\n    zap.AddCaller(),\n    zap.AddCallerSkip(1),\n    zap.AddStacktrace(zapcore.ErrorLevel),\n    log.ErrorOutput(\"stderr\"), // for internal errors\n    log.Sampling(100, 100),\n  )\n\n  // Set global logger\n  log.Use(logger)\n}\n\nfunc main() {\n  defer log.Sync()\n  defer log.CapturePanic() // optional, it logs unhandled panics before crashing\n\n  log.Error(\"Hello Production!\")\n}\n```\n\n## Changing log level\n\nUpdate the config to use a reference of [zap#AtomicLevel](https://godoc.org/go.uber.org/zap#NewAtomicLevel)\nthat you control. It can serve as [HTTP handler](https://godoc.org/go.uber.org/zap#AtomicLevel.ServeHTTP), too.\n\n\n## Replacing logger in third-party lib\n\nSometimes third-party libraries log on their own with no way of disabling it.\nWith the help of Go modules we can replace third-party logging libraries \nand instruct them to log through our logging infrastructure.\n\n  * [golang/glog](/glog)\n\n\n## Testing\n\nSome tests require credentials and configration that can't be commited to the repo.\nI recommend putting a `.env` file in each directory with contents like:\n\n```\nexport SLACK_URL='https://hooks.slack.com/services/xxx'\n```\n\nThen run test with `source .env \u0026\u0026 go test -v`\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattes%2Flog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattes%2Flog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattes%2Flog/lists"}