From 2c1d00185738ef2cd1fdbb6e55e5c2d95bebb91f Mon Sep 17 00:00:00 2001 From: Andy Xie Date: Fri, 6 Jan 2017 10:52:03 +0800 Subject: [PATCH] add error log for open log file --- utils/tail/tail.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utils/tail/tail.go b/utils/tail/tail.go index beccee36c1..88c7f72b8c 100644 --- a/utils/tail/tail.go +++ b/utils/tail/tail.go @@ -93,6 +93,7 @@ func (t *Tail) attemptOpen() error { defer t.readerLock.Unlock() t.readerErr = nil attempt := 0 + var lastErr error for interval := defaultRetryInterval; ; interval *= 2 { attempt++ glog.V(4).Infof("Opening %s (attempt %d)", t.filename, attempt) @@ -104,6 +105,9 @@ func (t *Tail) attemptOpen() error { t.reader = bufio.NewReader(t.file) return nil } + lastErr = err + glog.V(4).Infof("open log file %s error: %v", t.filename, err) + if interval >= maxRetryInterval { break } @@ -114,7 +118,7 @@ func (t *Tail) attemptOpen() error { return fmt.Errorf("watch was cancelled") } } - err := fmt.Errorf("can't open log file %s", t.filename) + err := fmt.Errorf("can't open log file %s: %v", t.filename, lastErr) t.readerErr = err return err }