forked from lestrrat-go/file-rotatelogs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
52 lines (46 loc) · 1.34 KB
/
options.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
package rotatelogs
import "time"
// Option is used to pass optional arguments to
// the Rotate constructor
type Option func(*Rotate)
// WithClock creates a new Option that sets a clock
// that the Rotate object will use to determine
// the current time.
//
// By default, rotatelogs.Local, which returns the
// current time in the local time zone, is used. If you
// would rather use UTC, use rotatelogs.UTC as the argument
// to this option, and pass it to the constructor.
func WithClock(c Clock) Option {
return func(rotate *Rotate) {
rotate.clock = c
}
}
// WithLocation creates a new Option that sets up a
// "Clock" interface that the Rotate object will use
// to determine the current time.
//
// This optin works by always returning the in the given
// location.
func WithLocation(location *time.Location) Option {
return func(rotate *Rotate) {
rotate.clock = clock(func() time.Time {
return time.Now().In(location)
})
}
}
// WithMaxAge creates a new Option that sets the
// max age of a log file before it gets purged from
// the file system.
func WithMaxAge(age time.Duration) Option {
return func(rotate *Rotate) {
rotate.maxAge = age
}
}
// WithRotationTime creates a new Option that sets the
// time between rotation.
func WithRotationTime(time time.Duration) Option {
return func(rotate *Rotate) {
rotate.rotationTime = time
}
}