{"id":13412756,"url":"https://github.com/snwfdhmp/errlog","last_synced_at":"2025-04-04T10:09:02.471Z","repository":{"id":57482210,"uuid":"171062239","full_name":"snwfdhmp/errlog","owner":"snwfdhmp","description":"Reduce debugging time. Use static \u0026 stack-trace analysis to identify the error immediately.","archived":false,"fork":false,"pushed_at":"2023-06-27T14:59:05.000Z","size":89,"stargazers_count":460,"open_issues_count":0,"forks_count":20,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-03T15:07:12.092Z","etag":null,"topics":["debugging-tool","error-log","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/snwfdhmp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"snwfdhmp"}},"created_at":"2019-02-16T23:19:05.000Z","updated_at":"2025-02-24T06:09:59.000Z","dependencies_parsed_at":"2024-01-30T04:55:46.073Z","dependency_job_id":null,"html_url":"https://github.com/snwfdhmp/errlog","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/snwfdhmp%2Ferrlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snwfdhmp%2Ferrlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snwfdhmp%2Ferrlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snwfdhmp%2Ferrlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/snwfdhmp","download_url":"https://codeload.github.com/snwfdhmp/errlog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247157283,"owners_count":20893220,"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":["debugging-tool","error-log","golang"],"created_at":"2024-07-30T20:01:28.790Z","updated_at":"2025-04-04T10:09:02.441Z","avatar_url":"https://github.com/snwfdhmp.png","language":"Go","readme":"# Errlog: reduce debugging time while programming [![Go Report Card](https://goreportcard.com/badge/github.com/snwfdhmp/errlog)](https://goreportcard.com/report/github.com/snwfdhmp/errlog) [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) [![Documentation](https://godoc.org/github.com/snwfdhmp/errlog?status.svg)](http://godoc.org/github.com/snwfdhmp/errlog) [![GitHub issues](https://img.shields.io/github/issues/snwfdhmp/errlog.svg)](https://github.com/snwfdhmp/errlog/issues) [![license](https://img.shields.io/github/license/snwfdhmp/errlog.svg?maxAge=6000)](https://github.com/snwfdhmp/errlog/LICENSE) \n\n![Example](https://i.imgur.com/Ulf1RGw.png)\n\n\u003ca href=\"https://www.buymeacoffee.com/snwfdhmp\" target=\"_blank\"\u003e\u003cimg src=\"https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png\" alt=\"Buy Me A Coffee\" style=\"height: 30px !important;width: 120px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;\" \u003e\u003c/a\u003e\n\n## Introduction\n\nUse errlog to improve error logging and **speed up  debugging while you create amazing code** :\n\n- Highlight source code\n- **Detect and point out** which func call is causing the fail\n- Pretty stack trace\n- **No-op mode** for production\n- Easy implementation, adaptable logger\n- Plug to any current project without changing you or your teammates habits\n- Plug to **your current logging system**\n\n|Go to|\n|---|\n|[Get started](#get-started)|\n|[Documentation](#documentation)|\n|[Examples](#example)|\n|[Tweaking](#tweak-as-you-need)|\n|[Feedbacks](#feedbacks)|\n|[Contributions](#contributions)|\n|[License](#license-information)|\n|[Contributors](#contributors)|\n\n## Get started\n\n### Install\n\n```shell\ngo get github.com/snwfdhmp/errlog\n```\n\n### Usage\n\nReplace your `if err != nil` with `if errlog.Debug(err)` to add debugging informations.\n\n```golang\nfunc someFunc() {\n    //...\n    if errlog.Debug(err) { // will debug \u0026 pass if err != nil, will ignore if err == nil\n        return\n    }\n}\n```\n\nIn production, call `errlog.DefaultLogger.Disable(true)` to enable no-op (equivalent to `if err != nil`)\n\n## Tweak as you need\n\nYou can configure your own logger with the following options :\n\n```golang\ntype Config struct {\n    PrintFunc          func(format string, data ...interface{}) //Printer func (eg: fmt.Printf)\n    LinesBefore        int  //How many lines to print *before* the error line when printing source code\n    LinesAfter         int  //How many lines to print *after* the error line when printing source code\n    PrintStack         bool //Shall we print stack trace ? yes/no\n    PrintSource        bool //Shall we print source code along ? yes/no\n    PrintError         bool //Shall we print the error of Debug(err) ? yes/no\n    ExitOnDebugSuccess bool //Shall we os.Exit(1) after Debug has finished logging everything ? (doesn't happen when err is nil). Will soon be replaced by ExitFunc to enable panic-ing the current goroutine. (if you need this quick, please open an issue)\n}\n```\n\n\u003e As we don't yet update automatically this README immediately when we add new features, this definition may be outdated. (Last update: 2019/08/07)\n\u003e [See the struct definition in godoc.org](https://godoc.org/github.com/snwfdhmp/errlog#Config) for the up to date definition\n\n\n## Example\n\n### Try yourself\n\n| Name and link | Description |\n| --- | --- |\n| [Basic](examples/basic/basic.go) | standard usage, quick setup\n| [Custom](examples/custom/custom.go) | guided configuration for fulfilling your needs |\n| [Disabled](examples/disabled/disabled.go) | how to disable the logging \u0026 debugging (eg: for production use) |\n| [Failing line far away](examples/failingLineFar/failingLineFar.go) | example of finding the func call that caused the error while it is lines away from the errlog.Debug call |\n| [Pretty stack trace](examples/stackTrace/stackTrace.go) | pretty stack trace printing instead of debugging. |\n\n### Just read\n\n#### Basic example\n\n\u003e Note that in the example, you will see some unuseful func. Those are made to generate additional stack trace levels for the sake of example\n\nWe're going to use this sample program :\n\n```golang\nfunc main() {\n    fmt.Println(\"Program start\")\n\n    wrapingFunc() //call to our important function\n\n    fmt.Println(\"Program end\")\n}\n\nfunc wrapingFunc() {\n    someBigFunction() // call some func \n}\n\nfunc someBigFunction() {\n    someDumbFunction() // just random calls\n    someSmallFunction() // just random calls\n    someDumbFunction() // just random calls\n\n    // Here it can fail, so instead of `if err  != nil` we use `errlog.Debug(err)`\n    if err := someNastyFunction(); errlog.Debug(err) {\n        return\n    }\n\n    someSmallFunction() // just random calls\n    someDumbFunction() // just random calls\n}\n\nfunc someSmallFunction() {\n    _ = fmt.Sprintf(\"I do things !\")\n}\n\nfunc someNastyFunction() error {\n    return errors.New(\"I'm failing for some reason\") // simulate an error\n}\n\nfunc someDumbFunction() bool {\n    return false // just random things\n}\n```\n\n\n#### Output\n\n![Console Output examples/basic.go](https://i.imgur.com/tOkDgwP.png)\n\n\nWe are able to **detect and point out which line is causing the error**.\n\n### Custom Configuration Example\n\nLet's see what we can do with a **custom configuration.**\n\n```golang\ndebug := errlog.NewLogger(\u0026errlog.Config{\n    // PrintFunc is of type `func (format string, data ...interface{})`\n    // so you can easily implement your own logger func.\n    // In this example, logrus is used, but any other logger can be used.\n    // Beware that you should add '\\n' at the end of format string when printing.\n    PrintFunc:          logrus.Printf,\n    PrintSource:        true, //Print the failing source code\n    LinesBefore:        2, //Print 2 lines before failing line\n    LinesAfter:         1, //Print 1 line after failing line\n    PrintError:         true, //Print the error\n    PrintStack:         false, //Don't print the stack trace\n    ExitOnDebugSuccess: true, //Exit if err\n})\n```\n\n\u003e Please note: This definition may be outdated. (Last update: 2019/08/07)\n\u003e [See the struct definition in godoc.org](https://godoc.org/github.com/snwfdhmp/errlog#Config) for the up to date definition\n\n#### Output\n\n![Console Output examples/custom.go](https://i.imgur.com/vh2iEnS.png)\n\n\n### When the failing func call is a few lines away\n\nEven when the func call is a few lines away, there is no problem for finding it.\n\n#### Output\n\n![Source Example: error earlier in the code](https://i.imgur.com/wPBrYqs.png)\n\n## Documentation\n\nDocumentation can be found here : [![Documentation](https://godoc.org/github.com/snwfdhmp/errlog?status.svg)](http://godoc.org/github.com/snwfdhmp/errlog)\n\n## Feedbacks\n\nFeel free to open an issue for any feedback or suggestion.\n\nI fix process issues quickly.\n\n## Contributions\n\nWe are happy to collaborate with you :\n\n- Ask for a new feature: [Open an issue](https://github.com/snwfdhmp/errlog/issues/new)\n- Add your feature: [Open a PR](https://github.com/snwfdhmp/errlog/compare)\n\nWhen submitting a PR, please apply Effective Go best practices. For more information: https://golang.org/doc/effective_go.html\n\n## License information\n\nClick the following badge to open LICENSE information.\n\n[![license](https://img.shields.io/github/license/snwfdhmp/errlog.svg?maxAge=60000)](https://github.com/snwfdhmp/errlog/LICENSE)\n\n## Contributors\n\n### Major\n\n- [snwfdhmp](https://github.com/snwfdhmp): Author and maintainer\n- [chemidy](https://github.com/chemidy): Added important badges\n\n### Minor fixes\n\n- [orisano](https://github.com/orisano)\n- [programmingman](https://github.com/programmingman)\n","funding_links":["https://github.com/sponsors/snwfdhmp","https://www.buymeacoffee.com/snwfdhmp"],"categories":["开源类库","Error Handling","Open source library","错误处理","Relational Databases","错误处理`go 语言错误处理库`"],"sub_categories":["错误处理","Search and Analytic Databases","Advanced Console UIs","Error Handling","检索及分析资料库","SQL 查询语句构建库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnwfdhmp%2Ferrlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsnwfdhmp%2Ferrlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnwfdhmp%2Ferrlog/lists"}