Skip to content

Latest commit

 

History

History
35 lines (28 loc) · 896 Bytes

README.md

File metadata and controls

35 lines (28 loc) · 896 Bytes

rotate

CircleCI Build status

A rotating file Writer

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
}