1package rotatelogs
2
3import (
4	"os"
5	"sync"
6	"time"
7
8	strftime "github.com/lestrrat/go-strftime"
9)
10
11// RotateLogs represents a log file that gets
12// automatically rotated as you write to it.
13type RotateLogs struct {
14	clock        Clock
15	curFn        string
16	globPattern  string
17	linkName     string
18	maxAge       time.Duration
19	mutex        sync.RWMutex
20	outFh        *os.File
21	pattern      *strftime.Strftime
22	rotationTime time.Duration
23}
24
25// Clock is the interface used by the RotateLogs
26// object to determine the current time
27type Clock interface {
28	Now() time.Time
29}
30type clockFn func() time.Time
31
32// UTC is an object satisfying the Clock interface, which
33// returns the current time in UTC
34var UTC = clockFn(func() time.Time { return time.Now().UTC() })
35
36// Local is an object satisfying the Clock interface, which
37// returns the current time in the local timezone
38var Local = clockFn(time.Now)
39
40// Option is used to pass optional arguments to
41// the RotateLogs constructor
42type Option interface {
43	Configure(*RotateLogs) error
44}
45
46// OptionFn is a type of Option that is represented
47// by a single function that gets called for Configure()
48type OptionFn func(*RotateLogs) error
49