https://github.com/kei2100/rotate
A rotating file Writer
https://github.com/kei2100/rotate
go golang log logging rotate writer
Last synced: 4 months ago
JSON representation
A rotating file Writer
- Host: GitHub
- URL: https://github.com/kei2100/rotate
- Owner: kei2100
- License: mit
- Created: 2019-05-20T13:03:24.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2026-02-23T05:55:50.000Z (4 months ago)
- Last Synced: 2026-02-23T13:51:43.607Z (4 months ago)
- Topics: go, golang, log, logging, rotate, writer
- Language: Go
- Homepage:
- Size: 47.9 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rotate
[](https://circleci.com/gh/kei2100/rotate)
[](https://ci.appveyor.com/project/kei2100/rotate/branch/master)
A rotating file Writer
```go
func ExampleWriter() {
dir, err := ioutil.TempDir("", "rotate-test")
if err != nil {
panic(err)
}
defer os.RemoveAll(dir)
const bytes3 int64 = 3
w, err := rotate.NewWriter(dir, "test.log", rotate.WithSizeBasedPolicy(bytes3))
if err != nil {
panic(err)
}
defer w.Close()
fmt.Fprint(w, "1")
fmt.Fprint(w, "2")
fmt.Fprint(w, "3")
time.Sleep(time.Second) // wait for rotate
fmt.Fprint(w, "4")
b0, _ := ioutil.ReadFile(filepath.Join(dir, "test.log"))
b1, _ := ioutil.ReadFile(filepath.Join(dir, "test.log.1"))
fmt.Printf("%s/%s", b0, b1)
// Output: 4/123
}
```