{"id":13413287,"url":"https://github.com/utahta/go-cronowriter","last_synced_at":"2025-04-12T02:44:02.445Z","repository":{"id":53741313,"uuid":"80907602","full_name":"utahta/go-cronowriter","owner":"utahta","description":"Time based rotating file writer","archived":false,"fork":false,"pushed_at":"2021-03-16T17:25:35.000Z","size":46,"stargazers_count":56,"open_issues_count":3,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-25T05:22:57.631Z","etag":null,"topics":["cronolog","go","golang","log","rotate","writer"],"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/utahta.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":"2017-02-04T09:02:55.000Z","updated_at":"2024-01-03T14:14:32.000Z","dependencies_parsed_at":"2022-08-25T00:21:59.567Z","dependency_job_id":null,"html_url":"https://github.com/utahta/go-cronowriter","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utahta%2Fgo-cronowriter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utahta%2Fgo-cronowriter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utahta%2Fgo-cronowriter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utahta%2Fgo-cronowriter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/utahta","download_url":"https://codeload.github.com/utahta/go-cronowriter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248507988,"owners_count":21115730,"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":["cronolog","go","golang","log","rotate","writer"],"created_at":"2024-07-30T20:01:36.876Z","updated_at":"2025-04-12T02:44:02.426Z","avatar_url":"https://github.com/utahta.png","language":"Go","funding_links":[],"categories":["Go","Logging","Logging 日志库","日志记录","日志","Relational Databases","\u003cspan id=\"日志-logging\"\u003e日志 Logging\u003c/span\u003e"],"sub_categories":["Search and Analytic Databases","SQL 查询语句构建库","Advanced Console UIs","检索及分析资料库","交流","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"# cronowriter\n\n[![GoDoc Reference](https://godoc.org/github.com/utahta/go-cronowriter?status.svg)](http://godoc.org/github.com/utahta/go-cronowriter)\n[![CircleCI](https://circleci.com/gh/utahta/go-cronowriter.svg?style=svg)](https://circleci.com/gh/utahta/go-cronowriter)\n[![codecov](https://codecov.io/gh/utahta/go-cronowriter/branch/master/graph/badge.svg)](https://codecov.io/gh/utahta/go-cronowriter)\n[![Go Report Card](https://goreportcard.com/badge/github.com/utahta/go-cronowriter)](https://goreportcard.com/report/github.com/utahta/go-cronowriter)\n[![GitHub release](https://img.shields.io/github/release/utahta/go-cronowriter.svg)](https://github.com/utahta/go-cronowriter/releases)\n\nThis is a simple file writer that it writes message to the specified format path.\n\nThe file path is constructed based on current date and time, like cronolog.\n\nThis project follows the [Semantic Versioning](https://semver.org/).\n\n## Installation\n\n```\n$ go get -u github.com/utahta/go-cronowriter\n```\n\n## Documentation\n\nAPI documentation can be found [here](http://godoc.org/github.com/utahta/go-cronowriter).\n\nThe format specifications can be found [here](https://github.com/lestrrat-go/strftime#supported-conversion-specifications).\n\n## Examples\n\n```go\nimport \"github.com/utahta/go-cronowriter\"\n```\n\n```go\nw := cronowriter.MustNew(\"/path/to/example.log.%Y%m%d\")\nw.Write([]byte(\"test\"))\n\n// output file\n// /path/to/example.log.20170204\n```\n\nYou can specify the directory as below\n```go\nw := cronowriter.MustNew(\"/path/to/%Y/%m/%d/example.log\")\nw.Write([]byte(\"test\"))\n\n// output file\n// /path/to/2017/02/04/example.log\n```\n\nwith Location\n```go\nw := cronowriter.MustNew(\"/path/to/example.log.%Z\", writer.WithLocation(time.UTC))\nw.Write([]byte(\"test\"))\n\n// output file\n// /path/to/example.log.UTC\n```\n\nwith Symlink\n```go\nw := cronowriter.MustNew(\"/path/to/example.log.%Y%m%d\", writer.WithSymlink(\"/path/to/example.log\"))\nw.Write([]byte(\"test\"))\n\n// output file\n// /path/to/example.log.20170204\n// /path/to/example.log -\u003e /path/to/example.log.20170204\n```\n\nwith Mutex\n```go\nw := cronowriter.MustNew(\"/path/to/example.log.%Y%m%d\", writer.WithMutex())\n```\n\nno use Mutex\n```go\nw := cronowriter.MustNew(\"/path/to/example.log.%Y%m%d\", writer.WithNopMutex())\n```\n\nwith Debug (stdout and stderr)\n```go\nw := cronowriter.MustNew(\"/path/to/example.log.%Y%m%d\", writer.WithDebug())\nw.Write([]byte(\"test\"))\n\n// output file, stdout and stderr\n// /path/to/example.log.20170204\n```\n\nwith Init\n```go\nw := cronowriter.MustNew(\"/path/to/example.log.%Y%m%d\", writer.WithInit())\n\n// open the file when New() method is called\n// /path/to/example.log.20170204\n```\n\n## Example using with zap\n\n### [uber-go/zap](https://github.com/uber-go/zap)\n\n```go\npackage main\n\nimport (\n\t\"github.com/utahta/go-cronowriter\"\n\t\"go.uber.org/zap\"\n\t\"go.uber.org/zap/zapcore\"\n)\n\nfunc main() {\n\tw1 := cronowriter.MustNew(\"/tmp/example.log.%Y%m%d\")\n\tw2 := cronowriter.MustNew(\"/tmp/internal_error.log.%Y%m%d\")\n\tl := zap.New(\n\t\tzapcore.NewCore(\n\t\t\tzapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),\n\t\t\tzapcore.AddSync(w1),\n\t\t\tzapcore.InfoLevel,\n\t\t),\n\t\tzap.ErrorOutput(zapcore.AddSync(w2)),\n\t)\n\tl.Info(\"test\")\n}\n\n// output\n// /tmp/example.log.20170204\n// {\"level\":\"info\",\"ts\":1486198722.1201255,\"msg\":\"test\"}\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/utahta/go-cronowriter/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futahta%2Fgo-cronowriter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Futahta%2Fgo-cronowriter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futahta%2Fgo-cronowriter/lists"}