{"id":13413307,"url":"https://github.com/azer/logger","last_synced_at":"2025-04-10T00:19:13.934Z","repository":{"id":21310874,"uuid":"24627405","full_name":"azer/logger","owner":"azer","description":"Minimalistic logging library for Go.","archived":false,"fork":false,"pushed_at":"2021-11-22T15:36:32.000Z","size":51,"stargazers_count":158,"open_issues_count":0,"forks_count":16,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-05-21T04:14:53.987Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://godoc.org/github.com/azer/logger","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azer.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}},"created_at":"2014-09-30T06:45:09.000Z","updated_at":"2024-01-03T14:11:39.000Z","dependencies_parsed_at":"2022-08-05T11:30:24.888Z","dependency_job_id":null,"html_url":"https://github.com/azer/logger","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azer%2Flogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azer%2Flogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azer%2Flogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azer%2Flogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azer","download_url":"https://codeload.github.com/azer/logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131468,"owners_count":21052853,"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-07-30T20:01:37.332Z","updated_at":"2025-04-10T00:19:13.909Z","avatar_url":"https://github.com/azer.png","language":"Go","readme":"## logger\n\nMinimalistic logging library for Go.\n**Features:**\n\n* [Advanced output filters (package and/or level)](#filters)\n* [Attributes](#attributes)\n* [Timers for measuring performance](#timers)\n* [Structured JSON output](#structured-output)\n* [Programmatical Usage](#programmatical-usage)\n* [Hooks](#hooks)\n* Being used in production since 2014.\n\n![](https://cldup.com/aVZBXEhcs2.png)\n\n## Install\n\n```bash\n$ go get github.com/azer/logger\n```\n\n## Getting Started\n\nCreate an instance with a preferred name;\n\n```go\nimport \"github.com/azer/logger\"\n\nvar log = logger.New(\"example-app\")\n```\n\nEvery logger has three methods: `Info`, `Timer` and `Error`.\n\n```go\nlog.Info(\"Running at %d\", 8080)\n\nerr := DoSomething()\n\nif err != nil {\n  log.Error(\"Failed: %s\", err.Error())\n}\n```\n\nDone. Now run your app, passing `LOG=*` environment variable. If you don't pass `LOG=*`, ([logging will be silent by default](http://www.linfo.org/rule_of_silence.html));\n\n```\n$ LOG=* go run example-app.go\n01:23:21.251 example-app Running at 8080\n```\n\nYou can filter logs by level, too. The hierarchy is; `mute`, `info`, `timer` and `error`.\nAfter the package selector, you can optionally specify minimum log level:\n\n```\n$ LOG=*@timer go run example-app.go\n01:23:21.251 example-app Running at 8080\n```\n\nThe above example will only show `timer` and `error` levels. If you choose `error`, it'll show only error logs.\n\nCheck out [examples](https://github.com/azer/logger/tree/master/examples) for a more detailed example.\n\n## Filters\n\nYou can enable all logs by specifying `*`:\n\n```bash\n$ LOG=* go run example-app.go\n```\n\nOr, choose specific packages that you want to see logs from:\n\n```bash\n$ LOG=images,users go run example-app.go\n```\n\nIn the above example, you'll only see logs from `images` and `users` packages. What if we want to see only `timer` and `error` level logs?\n\n```bash\n$ LOG=images@timer,users go run example-app.go\n```\n\n\nAnother example; show error logs from all packages, but hide logs from `database` package:\n\n```bash\n$ LOG=*@error,database@mute go run example-app.go\n```\n\n## Timers\n\nYou can use timer logs for measuring your program. For example;\n\n```go\ntimer := log.Timer()\n\nimage, err := PullImage(\"http://foo.com/bar.jpg\")\n\ntimer.End(\"Fetched foo.com/bar.jpg\")\n```\n\nTimer log lines will be outputting the elapsed time in time.Duration in a normal terminal, or in int64 format when your program is running on a non-terminal environment.\nSee below documentation for more info.\n\n## Structured Output\n\nWhen your app isn't running on a terminal, it'll change the output in JSON:\n\n```\n{ \"time\":\"2014-10-04 11:44:22.418595705 -0700 PDT\", \"package\":\"database\", \"level\":\"INFO\", \"msg\":\"Connecting to mysql://azer@localhost:9900/foobar\" }\n{ \"time\":\"2014-10-04 11:44:22.418600851 -0700 PDT\", \"package\":\"images\", \"level\":\"INFO\", \"msg\":\"Requesting an image at foo/bar.jpg\" }\n{ \"time\":\"2014-10-04 11:44:22.668645527 -0700 PDT\", \"package\":\"images\", \"level\":\"TIMER\", \"elapsed\":\"250032416\", \"msg\":\"Fetched foo/bar.jpg\" }\n{ \"time\":\"2014-10-04 11:44:22.668665527 -0700 PDT\", \"package\":\"database\", \"level\":\"ERROR\", \"msg\":\"Fatal connection error.\" }\n```\n\nSo you can parse \u0026 process the output easily. Here is a command that lets you see the JSON output in your terminal;\n\n```\nLOG=* go run examples/simple.go 2\u003e\u00261 | less\n```\n\n## Attributes\n\nTo add custom attributes to the structured output;\n\n```go\nlog.Info(\"Sending an e-mail...\", logger.Attrs{\n  \"from\": \"foo@bar.com\",\n  \"to\": \"qux@corge.com\",\n})\n```\n\nThe above log will appear in the structured output as:\n\n```go\n{ \"time\":\"2014-10-04 11:44:22.919726985 -0700 PDT\", \"package\":\"mail\", \"level\":\"INFO\", \"msg\":\"Sending an e-mail\", \"from\": \"foo@foobar.com\", \"to\": \"qux@corge.com\" }\n```\n\nIn your command-line as:\n\n![](https://cldup.com/FEzVDkEexs.png)\n\n## Programmatical Usage\n\nCustomizing the default behavior is easy. You can implement your own output;\n\n```go\nimport (\n  \"github.com/azer/logger\"\n)\n\ntype CustomWriter struct {}\n\nfunc (cw CustomWriter) Write (log *logger.Log) {\n  fmt.Println(\"custom log -\u003e \", log.Package, log.Level, log.Message, log.Attrs)\n}\n\nfunc main () {\n  logger.Hook(\u0026CustomWriter{})\n}\n```\n\nSee `examples/programmatical.go` for a working version of this example.\n\n## Hooks \n\n* [Slack](https://github.com/azer/logger-slack-hook): Stream logs into a Slack channel.\n","funding_links":[],"categories":["Relational Databases","Logging","日志记录","Logging 日志库","\u003cspan id=\"日志-logging\"\u003e日志 Logging\u003c/span\u003e","日志","日誌"],"sub_categories":["Advanced Console UIs","Search and Analytic Databases","检索及分析资料库","SQL 查询语句构建库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","交流","高級控制台界面","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazer%2Flogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazer%2Flogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazer%2Flogger/lists"}