{"id":16935594,"url":"https://github.com/codeskyblue/beelog","last_synced_at":"2025-04-11T18:54:07.890Z","repository":{"id":152244963,"uuid":"10859000","full_name":"codeskyblue/beelog","owner":"codeskyblue","description":"A simple log for Debug Trace Warn Error Critacal, extract code from astaxie/beego.","archived":false,"fork":false,"pushed_at":"2013-10-10T01:37:20.000Z","size":515,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T14:51:17.654Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeskyblue.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}},"created_at":"2013-06-22T04:48:13.000Z","updated_at":"2019-04-28T05:19:24.000Z","dependencies_parsed_at":"2023-04-09T18:43:07.715Z","dependency_job_id":null,"html_url":"https://github.com/codeskyblue/beelog","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/codeskyblue%2Fbeelog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeskyblue%2Fbeelog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeskyblue%2Fbeelog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeskyblue%2Fbeelog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeskyblue","download_url":"https://codeload.github.com/codeskyblue/beelog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248464699,"owners_count":21108238,"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-10-13T20:54:53.796Z","updated_at":"2025-04-11T18:54:07.865Z","avatar_url":"https://github.com/codeskyblue.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"*This project is not maintained anymore. Suggest to use* **[klog](https://github.com/shxsun/klog)**\n\n# beelog\n\nA simple log for Debug Trace Warn Error Critacal, extract code from astaxie/beego.\n\n\n## 日志处理\n\nbeelog默认有一个初始化的BeeLogger对象输出内容到stdout中，你可以通过如下的方式设置自己的输出：\n\n\tbeelog.SetLogger(*log.Logger)\n\n只要你的输出符合`*log.Logger`就可以，例如输出到文件：\n\n\tfd,err := os.OpenFile(\"/var/log/beeapp/beeapp.log\", os.O_RDWR|os.O_APPEND, 0644)\n\tif err != nil {\n\t\tbeelog.Critical(\"openfile beeapp.log:\", err)\n\t\treturn\n\t}\n\tlg := log.New(fd, \"\", log.Ldate|log.Ltime)\n\tbeelog.SetLogger(lg)\n\n\n### 不同级别的log日志函数\n\n* Trace(v ...interface{})\n* Debug(v ...interface{})\n* Info(v ...interface{})\n* Warn(v ...interface{})\n* Error(v ...interface{})\n* Critical(v ...interface{})\n\n你可以通过下面的方式设置不同的日志分级：\n\n\tbeelog.SetLevel(beelog.LevelError)\n\n当你代码中有很多日志输出之后，如果想上线，但是你不想输出Trace、Debug、Info等信息，那么你可以设置如下：\n\n\tbeelog.SetLevel(beelog.LevelWarning)\n\n这样的话就不会输出小于这个level的日志，日志的排序如下：\n\nLevelTrace、LevelDebug、LevelInfo、LevelWarning、LevelError、LevelCritical\n\n用户可以根据不同的级别输出不同的错误信息，如下例子所示：\n\n\n### Examples of log messages\n\n- Trace\n\n\t* \"Entered parse function validation block\"\n\t* \"Validation: entered second 'if'\"\n\t* \"Dictionary 'Dict' is empty. Using default value\"\n\n- Debug\n\n\t* \"Web page requested: http://somesite.com Params='...'\"\n\t* \"Response generated. Response size: 10000. Sending.\"\n\t* \"New file received. Type:PNG Size:20000\"\n\n- Info\n\n\t* \"Web server restarted\"\n\t* \"Hourly statistics: Requested pages: 12345 Errors: 123 ...\"\n\t* \"Service paused. Waiting for 'resume' call\"\n\n- Warn\n\n\t* \"Cache corrupted for file='test.file'. Reading from back-end\"\n\t* \"Database 192.168.0.7/DB not responding. Using backup 192.168.0.8/DB\"\n\t* \"No response from statistics server. Statistics not sent\"\n\n- Error\n\n\t* \"Internal error. Cannot process request #12345 Error:....\"\n\t* \"Cannot perform login: credentials DB not responding\"\n\n- Critical\n\n\t* \"Critical panic received: .... Shutting down\"\n\t* \"Fatal error: ... App is shutting down to prevent data corruption or loss\"\n\n\n### Example\n\n\tfunc internalCalculationFunc(x, y int) (result int, err error) {\n\t\tbeelog.Debug(\"calculating z. x:\", x, \" y:\", y)\n\t\tz := y\n\t\tswitch {\n\t\tcase x == 3:\n\t\t\tbeelog.Trace(\"x == 3\")\n\t\t\tpanic(\"Failure.\")\n\t\tcase y == 1:\n\t\t\tbeelog.Trace(\"y == 1\")\n\t\t\treturn 0, errors.New(\"Error!\")\n\t\tcase y == 2:\n\t\t\tbeelog.Trace(\"y == 2\")\n\t\t\tz = x\n\t\tdefault:\n\t\t\tbeelog.Trace(\"default\")\n\t\t\tz += x\n\t\t}\n\t\tretVal := z - 3\n\t\tbeelog.Debug(\"Returning \", retVal)\n\t\t\n\t\treturn retVal, nil\n\t}\n\t\n\tfunc processInput(input inputData) {\n\t\tdefer func() {\n\t\t\tif r := recover(); r != nil {\n\t\t\t\tbeelog.Error(\"Unexpected error occurred: \", r)\n\t\t\t\toutputs \u003c- outputData{result: 0, error: true}\n\t\t\t}\n\t\t}()\n\t\tbeelog.Info(\"Received input signal. x:\", input.x, \" y:\", input.y)\n\t\t\n\t\tres, err := internalCalculationFunc(input.x, input.y)\n\t\tif err != nil {\n\t\t\tbeelog.Warn(\"Error in calculation:\", err.Error())\n\t\t}\n\t\t\n\t\tbeelog.Info(\"Returning result: \", res, \" error: \", err)\n\t\toutputs \u003c- outputData{result: res, error: err != nil}\n\t}\n\t\n\tfunc main() {\n\t\tinputs = make(chan inputData)\n\t\toutputs = make(chan outputData)\n\t\tcriticalChan = make(chan int)\n\t\tbeelog.Info(\"App started.\")\n\t\t\n\t\tgo consumeResults(outputs)\n\t\tbeelog.Info(\"Started receiving results.\")\n\t\t\n\t\tgo generateInputs(inputs)\n\t\tbeelog.Info(\"Started sending signals.\")\n\t\t\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase input := \u003c-inputs:\n\t\t\t\tprocessInput(input)\n\t\t\tcase \u003c-criticalChan:\n\t\t\t\tbeelog.Critical(\"Caught value from criticalChan: Go shut down.\")\n\t\t\t\tpanic(\"Shut down due to critical fault.\")\n\t\t\t}\n\t\t}\n\t}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeskyblue%2Fbeelog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeskyblue%2Fbeelog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeskyblue%2Fbeelog/lists"}