forked from lestrrat-go/file-rotatelogs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinterface.go
73 lines (60 loc) · 1.46 KB
/
interface.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package rotatelogs
import (
"os"
"sync"
"time"
strftime "github.com/lestrrat-go/strftime"
)
type Handler interface {
Handle(Event)
}
type HandlerFunc func(Event)
type Event interface {
Type() EventType
}
type EventType int
const (
InvalidEventType EventType = iota
FileRotatedEventType
)
type FileRotatedEvent struct {
prev string // previous filename
current string // current, new filename
}
// RotateLogs represents a log file that gets
// automatically rotated as you write to it.
type RotateLogs struct {
clock Clock
curFn string
curBaseFn string
globPattern string
generation int
linkName string
maxAge time.Duration
mutex sync.RWMutex
eventHandler Handler
outFh *os.File
pattern *strftime.Strftime
rotationTime time.Duration
rotationSize int64
rotationCount uint
forceNewFile bool
}
// Clock is the interface used by the RotateLogs
// object to determine the current time
type Clock interface {
Now() time.Time
}
type clockFn func() time.Time
// UTC is an object satisfying the Clock interface, which
// returns the current time in UTC
var UTC = clockFn(func() time.Time { return time.Now().UTC() })
// Local is an object satisfying the Clock interface, which
// returns the current time in the local timezone
var Local = clockFn(time.Now)
// Option is used to pass optional arguments to
// the RotateLogs constructor
type Option interface {
Name() string
Value() interface{}
}