github.heygears.com/openimsdk/tools@v0.0.49/log/file-rotatelogs/interface.go (about)

     1  package rotatelogs
     2  
     3  import (
     4  	"os"
     5  	"sync"
     6  	"time"
     7  
     8  	strftime "github.com/lestrrat-go/strftime"
     9  )
    10  
    11  type Handler interface {
    12  	Handle(Event)
    13  }
    14  
    15  type HandlerFunc func(Event)
    16  
    17  type Event interface {
    18  	Type() EventType
    19  }
    20  
    21  type EventType int
    22  
    23  const (
    24  	InvalidEventType EventType = iota
    25  	FileRotatedEventType
    26  )
    27  
    28  type FileRotatedEvent struct {
    29  	prev    string // previous filename
    30  	current string // current, new filename
    31  }
    32  
    33  // RotateLogs represents a log file that gets
    34  // automatically rotated as you write to it.
    35  type RotateLogs struct {
    36  	clock         Clock
    37  	curFn         string
    38  	curBaseFn     string
    39  	globPattern   string
    40  	generation    int
    41  	linkName      string
    42  	maxAge        time.Duration
    43  	mutex         sync.RWMutex
    44  	eventHandler  Handler
    45  	outFh         *os.File
    46  	pattern       *strftime.Strftime
    47  	rotationTime  time.Duration
    48  	rotationSize  int64
    49  	rotationCount uint
    50  	forceNewFile  bool
    51  }
    52  
    53  // Clock is the interface used by the RotateLogs
    54  // object to determine the current time
    55  type Clock interface {
    56  	Now() time.Time
    57  }
    58  type clockFn func() time.Time
    59  
    60  // UTC is an object satisfying the Clock interface, which
    61  // returns the current time in UTC
    62  var UTC = clockFn(func() time.Time { return time.Now().UTC() })
    63  
    64  // Local is an object satisfying the Clock interface, which
    65  // returns the current time in the local timezone
    66  var Local = clockFn(time.Now)
    67  
    68  // Option is used to pass optional arguments to
    69  // the RotateLogs constructor
    70  type Option interface {
    71  	Name() string
    72  	Value() interface{}
    73  }