WithFlushPeriod creates a new BufferedLoggerOption that sets the flush period for the BufferedLogger.
(d time.Duration)
| 68 | |
| 69 | // WithFlushPeriod creates a new BufferedLoggerOption that sets the flush period for the BufferedLogger. |
| 70 | func WithFlushPeriod(d time.Duration) BufferedLoggerOption { |
| 71 | return func(l *BufferedLogger) { |
| 72 | go func() { |
| 73 | tick := time.NewTicker(d) |
| 74 | defer tick.Stop() |
| 75 | |
| 76 | for range tick.C { |
| 77 | l.Flush() |
| 78 | } |
| 79 | }() |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // WithFlushCallback allows for a callback function to be executed when Flush() is called. |
| 84 | // The length of the buffer at the time of the Flush() will be passed to the function. |