This repository has been archived by the owner on Jul 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
/
options.go
89 lines (77 loc) · 2.56 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package rotatelogs
import (
"time"
"github.com/lestrrat-go/file-rotatelogs/internal/option"
)
const (
optkeyClock = "clock"
optkeyHandler = "handler"
optkeyLinkName = "link-name"
optkeyMaxAge = "max-age"
optkeyRotationTime = "rotation-time"
optkeyRotationSize = "rotation-size"
optkeyRotationCount = "rotation-count"
optkeyForceNewFile = "force-new-file"
)
// WithClock creates a new Option that sets a clock
// that the RotateLogs 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 option.New(optkeyClock, c)
}
// WithLocation creates a new Option that sets up a
// "Clock" interface that the RotateLogs object will use
// to determine the current time.
//
// This optin works by always returning the in the given
// location.
func WithLocation(loc *time.Location) Option {
return option.New(optkeyClock, clockFn(func() time.Time {
return time.Now().In(loc)
}))
}
// WithLinkName creates a new Option that sets the
// symbolic link name that gets linked to the current
// file name being used.
func WithLinkName(s string) Option {
return option.New(optkeyLinkName, s)
}
// WithMaxAge creates a new Option that sets the
// max age of a log file before it gets purged from
// the file system.
func WithMaxAge(d time.Duration) Option {
return option.New(optkeyMaxAge, d)
}
// WithRotationTime creates a new Option that sets the
// time between rotation.
func WithRotationTime(d time.Duration) Option {
return option.New(optkeyRotationTime, d)
}
// WithRotationSize creates a new Option that sets the
// log file size between rotation.
func WithRotationSize(s int64) Option {
return option.New(optkeyRotationSize, s)
}
// WithRotationCount creates a new Option that sets the
// number of files should be kept before it gets
// purged from the file system.
func WithRotationCount(n uint) Option {
return option.New(optkeyRotationCount, n)
}
// WithHandler creates a new Option that specifies the
// Handler object that gets invoked when an event occurs.
// Currently `FileRotated` event is supported
func WithHandler(h Handler) Option {
return option.New(optkeyHandler, h)
}
// ForceNewFile ensures a new file is created every time New()
// is called. If the base file name already exists, an implicit
// rotation is performed
func ForceNewFile() Option {
return option.New(optkeyForceNewFile, true)
}