OSDN Git Service

add bytom logs into files
[bytom/bytom.git] / vendor / github.com / lestrrat-go / file-rotatelogs / options.go
1 package rotatelogs
2
3 import (
4         "time"
5
6         "github.com/lestrrat-go/file-rotatelogs/internal/option"
7 )
8
9 const (
10         optkeyClock         = "clock"
11         optkeyHandler       = "handler"
12         optkeyLinkName      = "link-name"
13         optkeyMaxAge        = "max-age"
14         optkeyRotationTime  = "rotation-time"
15         optkeyRotationCount = "rotation-count"
16         optkeyForceNewFile  = "force-new-file"
17 )
18
19 // WithClock creates a new Option that sets a clock
20 // that the RotateLogs object will use to determine
21 // the current time.
22 //
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)
29 }
30
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.
34 //
35 // This optin works by always returning the in the given
36 // location.
37 func WithLocation(loc *time.Location) Option {
38         return option.New(optkeyClock, clockFn(func() time.Time {
39                 return time.Now().In(loc)
40         }))
41 }
42
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)
48 }
49
50 // WithMaxAge creates a new Option that sets the
51 // max age of a log file before it gets purged from
52 // the file system.
53 func WithMaxAge(d time.Duration) Option {
54         return option.New(optkeyMaxAge, d)
55 }
56
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)
61 }
62
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)
68 }
69
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)
75 }
76
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)
82 }