diff options
Diffstat (limited to 'internal/io/dlog/rotation.go')
| -rw-r--r-- | internal/io/dlog/rotation.go | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/internal/io/dlog/rotation.go b/internal/io/dlog/rotation.go index 15ce1fd..e2a1bb8 100644 --- a/internal/io/dlog/rotation.go +++ b/internal/io/dlog/rotation.go @@ -12,16 +12,20 @@ import ( func rotation(ctx context.Context) { rotateCh := make(chan os.Signal, 1) signal.Notify(rotateCh, syscall.SIGHUP) - go func() { - for { - select { - case <-rotateCh: - Common.Debug("Invoking log rotation") - loggers.FactoryRotate() - return - case <-ctx.Done(): - return - } + go rotateLoop(ctx, rotateCh, loggers.FactoryRotate) +} + +// rotateLoop services the log-rotation channel until ctx is cancelled. It is +// split out from rotation so tests can drive it directly with a fake rotate +// function and a test-owned channel. +func rotateLoop(ctx context.Context, rotateCh <-chan os.Signal, rotate func()) { + for { + select { + case <-rotateCh: + Common.Debug("Invoking log rotation") + rotate() + case <-ctx.Done(): + return } - }() + } } |
