6 "github.com/lestrrat-go/file-rotatelogs/internal/option"
11 optkeyHandler = "handler"
12 optkeyLinkName = "link-name"
13 optkeyMaxAge = "max-age"
14 optkeyRotationTime = "rotation-time"
15 optkeyRotationCount = "rotation-count"
16 optkeyForceNewFile = "force-new-file"
19 // WithClock creates a new Option that sets a clock
20 // that the RotateLogs object will use to determine
23 // By default rotatelogs.Local, which returns the
24 // current time in the local time zone, is used. If you
25 // would rather use UTC, use rotatelogs.UTC as the argument
26 // to this option, and pass it to the constructor.
27 func WithClock(c Clock) Option {
28 return option.New(optkeyClock, c)
31 // WithLocation creates a new Option that sets up a
32 // "Clock" interface that the RotateLogs object will use
33 // to determine the current time.
35 // This optin works by always returning the in the given
37 func WithLocation(loc *time.Location) Option {
38 return option.New(optkeyClock, clockFn(func() time.Time {
39 return time.Now().In(loc)
43 // WithLinkName creates a new Option that sets the
44 // symbolic link name that gets linked to the current
45 // file name being used.
46 func WithLinkName(s string) Option {
47 return option.New(optkeyLinkName, s)
50 // WithMaxAge creates a new Option that sets the
51 // max age of a log file before it gets purged from
53 func WithMaxAge(d time.Duration) Option {
54 return option.New(optkeyMaxAge, d)
57 // WithRotationTime creates a new Option that sets the
58 // time between rotation.
59 func WithRotationTime(d time.Duration) Option {
60 return option.New(optkeyRotationTime, d)
63 // WithRotationCount creates a new Option that sets the
64 // number of files should be kept before it gets
65 // purged from the file system.
66 func WithRotationCount(n uint) Option {
67 return option.New(optkeyRotationCount, n)
70 // WithHandler creates a new Option that specifies the
71 // Handler object that gets invoked when an event occurs.
72 // Currently `FileRotated` event is supported
73 func WithHandler(h Handler) Option {
74 return option.New(optkeyHandler, h)
77 // ForceNewFile ensures a new file is created every time New()
78 // is called. If the base file name already exists, an implicit
79 // rotation is performed
80 func ForceNewFile() Option {
81 return option.New(optkeyForceNewFile, true)