OSDN Git Service

fcd0f58a552d3f827822641e5a74572ae7d16c7b
[bytom/vapor.git] / vendor / github.com / lestrrat-go / file-rotatelogs / interface.go
1 package rotatelogs
2
3 import (
4         "os"
5         "sync"
6         "time"
7
8         strftime "github.com/lestrrat-go/strftime"
9 )
10
11 type Handler interface {
12         Handle(Event)
13 }
14
15 type HandlerFunc func(Event)
16
17 type Event interface {
18         Type() EventType
19 }
20
21 type EventType int
22
23 const (
24         InvalidEventType EventType = iota
25         FileRotatedEventType
26 )
27
28 type FileRotatedEvent struct {
29         prev    string // previous filename
30         current string // current, new filename
31 }
32
33 // RotateLogs represents a log file that gets
34 // automatically rotated as you write to it.
35 type RotateLogs struct {
36         clock         Clock
37         curFn         string
38         curBaseFn     string
39         globPattern   string
40         generation    int
41         linkName      string
42         maxAge        time.Duration
43         mutex         sync.RWMutex
44         eventHandler  Handler
45         outFh         *os.File
46         pattern       *strftime.Strftime
47         rotationTime  time.Duration
48         rotationCount uint
49         forceNewFile  bool
50 }
51
52 // Clock is the interface used by the RotateLogs
53 // object to determine the current time
54 type Clock interface {
55         Now() time.Time
56 }
57 type clockFn func() time.Time
58
59 // UTC is an object satisfying the Clock interface, which
60 // returns the current time in UTC
61 var UTC = clockFn(func() time.Time { return time.Now().UTC() })
62
63 // Local is an object satisfying the Clock interface, which
64 // returns the current time in the local timezone
65 var Local = clockFn(time.Now)
66
67 // Option is used to pass optional arguments to
68 // the RotateLogs constructor
69 type Option interface {
70         Name() string
71         Value() interface{}
72 }