{"id":13819906,"url":"https://github.com/lyuangg/ylog","last_synced_at":"2025-06-15T02:04:09.156Z","repository":{"id":64411325,"uuid":"564651027","full_name":"lyuangg/ylog","owner":"lyuangg","description":"go log","archived":false,"fork":false,"pushed_at":"2023-02-07T04:08:06.000Z","size":15,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T18:46:20.904Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lyuangg.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-11-11T07:11:31.000Z","updated_at":"2023-10-29T09:00:03.000Z","dependencies_parsed_at":"2024-01-13T16:22:07.144Z","dependency_job_id":"73e561b1-e64d-4116-91cb-c1ee323a913d","html_url":"https://github.com/lyuangg/ylog","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/lyuangg/ylog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lyuangg%2Fylog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lyuangg%2Fylog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lyuangg%2Fylog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lyuangg%2Fylog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lyuangg","download_url":"https://codeload.github.com/lyuangg/ylog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lyuangg%2Fylog/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259910672,"owners_count":22930703,"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-08-04T08:00:54.769Z","updated_at":"2025-06-15T02:04:09.114Z","avatar_url":"https://github.com/lyuangg.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# ylog\n\n![GitHub](https://img.shields.io/github/license/lyuangg/ylog?style=flat-square)\n![GitHub go.mod Go version (subdirectory of monorepo)](https://img.shields.io/github/go-mod/go-version/lyuangg/ylog?style=flat-square\u0026logo=go)\n![test coverage](https://img.shields.io/badge/test-100%25-brightgreen?style=flat-square)\n![GitHub Repo stars](https://img.shields.io/github/stars/lyuangg/ylog?style=flat-square)\n\n\n一个简单易用的 go 日志库。 [设计](http://yuancoder.com/ylog/)\n\n## Features\n\n- 支持日志级别: debug, info, warning, error\n- 支持按日期旋转文件\n- 支持 json 格式\n- 支持自定义格式和输出\n- 代码测试覆盖率 100%\n- 线程安全的\n- 超越 `sirupsen/logrus` 日志库的性能\n\n## Install\n\n```\ngo get -u github.com/lyuangg/ylog\n```\n\n## Usage\n\n```go\n// 基本使用\nylog.Info(\"hello\")\n\nylog.Infof(\"hello %d\", 1)\n\nylog.Debug(\"debug msg..\")\n\nylog.Errorf(\"err msg: %s, %v\", \"err\", \"msg\")\n\n// json\nylog.SetFormatter(NewJsonFormatter())\n\n// 自定义字段\nylog.With(Fields{\n    \"requestid\" : \"123456\",\n    \"traceid\" : 5555,\n}).Info(\"hello ylog\")\n\n// 按日期旋转文件\nouter := ylog.NewRotateFile(\"./testdata\", \"go-2006-01-02.log\", 7)\nylog.SetOuter(outer)\n\n// 设置日志级别\nylog.SetLevel(ylog.ParseLevel(\"debug\"))\nylog.SetLevel(ylog.DebugLevel)\n\n// new logger\nnewlog := ylog.New()\nnewlog.SetLevel(ylog.WarnLevel)\n\n// 自定义格式和输出, 实现下面两个接口，调用 SetFormatter，SetOuter 方法\ntype (\n    Formatter interface {\n\t\tFormat(r Record) (string, error)\n\t}\n\n    Outer interface {\n\t\tWrite(r Record) error\n\t}\n)\n```\n\n## Test\n\n```bash\ngo test -cover\n```\n\noutput:\n\n```bash\nPASS\ncoverage: 100.0% of statements\nok      github.com/lyuangg/ylog 0.109s\n```\n\n## Benchmark\n\n```bash\ngo test -bench=. -benchtime=3s -benchmem -run=none\n```\n\n```bash\ngoos: darwin\ngoarch: amd64\npkg: github.com/lyuangg/ylog/benchmarks\ncpu: Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz\nBenchmarkDefaultLogger/logrus-8                  1528854              2652 ns/op             576 B/op         17 allocs/op\nBenchmarkDefaultLogger/ylog-8                   11159875               307.4 ns/op           276 B/op          6 allocs/op\nBenchmarkRoateLogger/logrus-8                     250870             13076 ns/op             945 B/op         21 allocs/op\nBenchmarkRoateLogger/ylog-8                       622275              5385 ns/op             292 B/op          8 allocs/op\nBenchmarkWithField/logrus-8                      1000000              3094 ns/op             881 B/op         18 allocs/op\nBenchmarkWithField/ylog-8                        8655415               387.6 ns/op           500 B/op          7 allocs/op\nBenchmarkJsonFormat/logrus-8                      879865              3747 ns/op            1682 B/op         29 allocs/op\nBenchmarkJsonFormat/ylog-8                       3995971               999.0 ns/op          1585 B/op         25 allocs/op\nPASS\nok      github.com/lyuangg/ylog/benchmarks      32.649s\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flyuangg%2Fylog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flyuangg%2Fylog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flyuangg%2Fylog/lists"}