@@ -4,10 +4,12 @@ import (
44 "context"
55 "fmt"
66 "os"
7+ "time"
78
89 "github.com/containers/podman/v3/libpod/define"
910 "github.com/containers/podman/v3/libpod/events"
1011 "github.com/containers/podman/v3/libpod/logs"
12+ "github.com/hpcloud/tail/watch"
1113 "github.com/pkg/errors"
1214 "github.com/sirupsen/logrus"
1315)
@@ -74,7 +76,7 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption
7476 }
7577 nll , err := logs .NewLogLine (line .Text )
7678 if err != nil {
77- logrus .Error ( err )
79+ logrus .Errorf ( "Error getting new log line: %v" , err )
7880 continue
7981 }
8082 if nll .Partial () {
@@ -93,17 +95,20 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption
9395 }()
9496 // Check if container is still running or paused
9597 if options .Follow {
98+ // If the container isn't running or if we encountered an error
99+ // getting its state, instruct the logger to read the file
100+ // until EOF.
96101 state , err := c .State ()
97102 if err != nil || state != define .ContainerStateRunning {
98- // If the container isn't running or if we encountered
99- // an error getting its state, instruct the logger to
100- // read the file until EOF.
103+ // Make sure to wait at least for the poll duration
104+ // before stopping the file logger (see #10675).
105+ time . Sleep ( watch . POLL_DURATION )
101106 tailError := t .StopAtEOF ()
102107 if tailError != nil && fmt .Sprintf ("%v" , tailError ) != "tail: stop at eof" {
103- logrus .Error ( tailError )
108+ logrus .Errorf ( "Error stopping logger: %v" , tailError )
104109 }
105- if errors .Cause (err ) != define .ErrNoSuchCtr {
106- logrus .Error ( err )
110+ if err != nil && errors .Cause (err ) != define .ErrNoSuchCtr {
111+ logrus .Errorf ( "Error getting container state: %v" , err )
107112 }
108113 return nil
109114 }
@@ -124,9 +129,12 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption
124129 // Now wait for the died event and signal to finish
125130 // reading the log until EOF.
126131 <- eventChannel
132+ // Make sure to wait at least for the poll duration
133+ // before stopping the file logger (see #10675).
134+ time .Sleep (watch .POLL_DURATION )
127135 tailError := t .StopAtEOF ()
128136 if tailError != nil && fmt .Sprintf ("%v" , tailError ) != "tail: stop at eof" {
129- logrus .Error ( tailError )
137+ logrus .Errorf ( "Error stopping logger: %v" , tailError )
130138 }
131139 }()
132140 }
0 commit comments