writer_test.go 664 字节
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
package goku_log

import (
	"context"
	"fmt"
	"testing"
	"time"
)

type MinPeriod struct {

}

func (p *MinPeriod) String() string {
	return "Minute"
}

func (p *MinPeriod) FormatLayout() string {
	return "200601021504"
}

func TestFileWriterByPeriod(t *testing.T) {
	w:=NewFileWriteBytePeriod("/Users/huangmengzhu/test/log","app.log",new(MinPeriod))
	defer w.Close()
	ctx,_:=context.WithTimeout(context.Background(),time.Minute*3)

	tick:=time.NewTicker(time.Millisecond)
	defer tick.Stop()
	index:= 0

	for {
		select {
		case  <-ctx.Done():
			{
				w.Close()
				return

			}
		case <-tick.C:
			{
				index++
				fmt.Fprintf(w,"line:%d\n",index)
			}
		}
	}
}