gitee.com/lh-her-team/common@v1.5.1/log/file-rotatelogs/options.go (about) 1 package rotatelogs 2 3 import ( 4 "time" 5 6 "gitee.com/lh-her-team/common/log/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 optkeyRotationSize = "rotation-size" 16 optkeyRotationCount = "rotation-count" 17 optkeyForceNewFile = "force-new-file" 18 ) 19 20 // WithClock creates a new Option that sets a clock 21 // that the RotateLogs object will use to determine 22 // the current time. 23 // 24 // By default rotatelogs.Local, which returns the 25 // current time in the local time zone, is used. If you 26 // would rather use UTC, use rotatelogs.UTC as the argument 27 // to this option, and pass it to the constructor. 28 func WithClock(c Clock) Option { 29 return option.New(optkeyClock, c) 30 } 31 32 // WithLocation creates a new Option that sets up a 33 // "Clock" interface that the RotateLogs object will use 34 // to determine the current time. 35 // 36 // This optin works by always returning the in the given 37 // location. 38 func WithLocation(loc *time.Location) Option { 39 return option.New(optkeyClock, clockFn(func() time.Time { 40 return time.Now().In(loc) 41 })) 42 } 43 44 // WithLinkName creates a new Option that sets the 45 // symbolic link name that gets linked to the current 46 // file name being used. 47 func WithLinkName(s string) Option { 48 return option.New(optkeyLinkName, s) 49 } 50 51 // WithMaxAge creates a new Option that sets the 52 // max age of a log file before it gets purged from 53 // the file system. 54 func WithMaxAge(d time.Duration) Option { 55 return option.New(optkeyMaxAge, d) 56 } 57 58 // WithRotationTime creates a new Option that sets the 59 // time between rotation. 60 func WithRotationTime(d time.Duration) Option { 61 return option.New(optkeyRotationTime, d) 62 } 63 64 // WithRotationSize creates a new Option that sets the 65 // log file size between rotation. 66 func WithRotationSize(s int64) Option { 67 return option.New(optkeyRotationSize, s) 68 } 69 70 // WithRotationCount creates a new Option that sets the 71 // number of files should be kept before it gets 72 // purged from the file system. 73 func WithRotationCount(n uint) Option { 74 return option.New(optkeyRotationCount, n) 75 } 76 77 // WithHandler creates a new Option that specifies the 78 // Handler object that gets invoked when an event occurs. 79 // Currently `FileRotated` event is supported 80 func WithHandler(h Handler) Option { 81 return option.New(optkeyHandler, h) 82 } 83 84 // ForceNewFile ensures a new file is created every time New() 85 // is called. If the base file name already exists, an implicit 86 // rotation is performed 87 func ForceNewFile() Option { 88 return option.New(optkeyForceNewFile, true) 89 }