logs: k8s-file: fix spurious error logs

Fix the suprious "Error: nil" messages.  Also add some more context to
logged error messages which makes error sources more obvious.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2021-06-21 14:11:27 +02:00
parent 9ec4d04592
commit f4ba433b18

View File

@ -74,7 +74,7 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption
} }
nll, err := logs.NewLogLine(line.Text) nll, err := logs.NewLogLine(line.Text)
if err != nil { if err != nil {
logrus.Error(err) logrus.Errorf("Error getting new log line: %v", err)
continue continue
} }
if nll.Partial() { if nll.Partial() {
@ -100,10 +100,10 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption
// read the file until EOF. // read the file until EOF.
tailError := t.StopAtEOF() tailError := t.StopAtEOF()
if tailError != nil && fmt.Sprintf("%v", tailError) != "tail: stop at eof" { if tailError != nil && fmt.Sprintf("%v", tailError) != "tail: stop at eof" {
logrus.Error(tailError) logrus.Errorf("Error stopping logger: %v", tailError)
} }
if errors.Cause(err) != define.ErrNoSuchCtr { if err != nil && errors.Cause(err) != define.ErrNoSuchCtr {
logrus.Error(err) logrus.Errorf("Error getting container state: %v", err)
} }
return nil return nil
} }
@ -126,7 +126,7 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption
<-eventChannel <-eventChannel
tailError := t.StopAtEOF() tailError := t.StopAtEOF()
if tailError != nil && fmt.Sprintf("%v", tailError) != "tail: stop at eof" { if tailError != nil && fmt.Sprintf("%v", tailError) != "tail: stop at eof" {
logrus.Error(tailError) logrus.Errorf("Error stopping logger: %v", tailError)
} }
}() }()
} }