{"id":47814260,"url":"https://github.com/xfali/xlog","last_synced_at":"2026-04-03T18:22:17.627Z","repository":{"id":49790512,"uuid":"290518652","full_name":"xfali/xlog","owner":"xfali","description":"Logging for Go","archived":false,"fork":false,"pushed_at":"2022-01-21T16:46:07.000Z","size":191,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-07-27T16:15:28.684Z","etag":null,"topics":["logging","logr"],"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/xfali.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":"2020-08-26T14:26:24.000Z","updated_at":"2022-01-21T16:46:10.000Z","dependencies_parsed_at":"2022-09-11T16:11:01.476Z","dependency_job_id":null,"html_url":"https://github.com/xfali/xlog","commit_stats":null,"previous_names":[],"tags_count":9,"template":null,"template_full_name":null,"purl":"pkg:github/xfali/xlog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fxlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fxlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fxlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fxlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xfali","download_url":"https://codeload.github.com/xfali/xlog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xfali%2Fxlog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31368169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T17:53:18.093Z","status":"ssl_error","status_checked_at":"2026-04-03T17:53:17.617Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["logging","logr"],"created_at":"2026-04-03T18:22:17.078Z","updated_at":"2026-04-03T18:22:17.592Z","avatar_url":"https://github.com/xfali.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xlog\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/xfali/xlog)](https://goreportcard.com/report/github.com/xfali/xlog)\n[![Go Reference](https://pkg.go.dev/badge/github.com/xfali/xlog.svg)](https://pkg.go.dev/github.com/xfali/xlog)\n[![Build status](https://ci.appveyor.com/api/projects/status/ajcpxxgvp10n6dmp?svg=true)](https://ci.appveyor.com/project/xfali/xlog)\n\nxlog是一个go日志框架，提供简单易用的日志[API](logger.go)。\n\nxlog同时实现了[logr API (v0.2.0)](https://github.com/go-logr/logr) (xlogr)\n\nxlog各层可以自行实现接口进行替换，根据实际业务进行配置:\n\n\n![alt](docs/images/xlog.png)\n\n## 安装\n```\ngo get github.com/xfali/xlog\n```\n\n## 使用\n\n### 1. 快速入门\n```\nlogger := xlog.GetLogger()\nlogger.Infof(\"hello %s\\n\", \"world\")\nlogger.Panic(\"panic !\")\n\n// 或使用默认函数\nxlog.Infof(\"hello %s\\n\", \"world\")\nxlog.Panic(\"panic !\")\n```\n\n### 2. 配置日志级别\nxlog共支持6个日志级别：\n|  类型   | 说明  |\n|  :----  | :----  |\n| DEBUG  | 最低级别，默认不输出 |\n| INFO  |  默认的日志级别 |\n| WARN  |  警告级别  |\n| ERROR  | 错误级别 |\n| PANIC  | Panic级别，会触发panic,参数类型为xlog.KeyValues（内置logging可配置panic函数）|\n| FATAL  | 致命错误，会触发程序退出（内置logging可配置退出函数） |\n```\nxlog.SetSeverityLevel(xlog.WARN)\n```\n\n### 3. 配置输出Writer\nxlog默认输出到os.Stdout，可以通过下面方法配置输出的writer\n```\n// 所有日志级别统一配置为参数的输出writer\nxlog.SetOutput(w)\n\n// 或者按日志级别配置输出writer\nxlog.SetOutputBySeverity(xlog.WARN, w)\n```\n\n### 4. 配置日志格式Formatter\n内置支持的Formatter有：\n* xlog.TextFormatter\n* xlog.JsonFormatter\n```\nxlog.SetFormatter(f)\n```\n\n### 5. 使用logr API\n```\nlogr := xlogr.NewLogr()\nlogr.Info(\"this is a test\", \"time\", time.Now(), \"float\", 3.14)\n```\n\n## 内置Writer\nxlog内置的输出writer有：\n* AsyncBufferLogWriter: 线程安全的异步带缓存的writer\n* AsyncLogWriter: 线程安全的异步无缓存的writer\n* RotateFileWriter: 滚动记录日志的writer\n\n(一般RotateFileWriter结合AsyncBufferLogWriter使用)\n\n也可以使用第三方输出writer，如：\n\n[file-rotatelogs](https://github.com/lestrrat-go/file-rotatelogs)\n### \n使用内置输出writer配置如下(详细配置请参考参数的注释说明)：\n```\nw := writer.NewRotateFileWriter(\u0026writer.RotateFile{\n\t\tPath:            \"./test.log\",\n\t\tRotateFrequency: writer.RotateEveryDay,\n\t\tRotateFunc:      writer.ZipLogsAsync,\n\t}, writer.Config{\n\t\n\t})\nxlog.SetOutput(w)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxfali%2Fxlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxfali%2Fxlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxfali%2Fxlog/lists"}