@@ -157,46 +157,37 @@ func viewLogsJSONFileDirect(lvopts LogViewOptions, jsonLogFilePath string, stdou
157
157
return fmt .Errorf ("error occurred while trying to seek JSON logfile %q at position %d: %s" , jsonLogFilePath , lastPos , err )
158
158
}
159
159
fin .Close ()
160
-
161
- readFromLastPos := func () error {
162
- // Re-open the file and seek to the last-consumed offset.
163
- fin , err = os .OpenFile (jsonLogFilePath , os .O_RDONLY , 0400 )
164
- if err != nil {
165
- fin .Close ()
166
- return fmt .Errorf ("error occurred while trying to re-open JSON logfile %q: %s" , jsonLogFilePath , err )
167
- }
168
- _ , err = fin .Seek (lastPos , 0 )
169
- if err != nil {
170
- fin .Close ()
171
- return fmt .Errorf ("error occurred while trying to seek JSON logfile %q at position %d: %s" , jsonLogFilePath , lastPos , err )
172
- }
173
-
174
- err = jsonfile .Decode (stdout , stderr , fin , lvopts .Timestamps , lvopts .Since , lvopts .Until , 0 )
175
- if err != nil {
176
- fin .Close ()
177
- return fmt .Errorf ("error occurred while doing follow-up decoding of JSON logfile %q at starting position %d: %s" , jsonLogFilePath , lastPos , err )
178
- }
179
-
180
- // Record current file seek position before looping again.
181
- lastPos , err = fin .Seek (0 , io .SeekCurrent )
182
- if err != nil {
183
- fin .Close ()
184
- return fmt .Errorf ("error occurred while trying to seek JSON logfile %q at current position: %s" , jsonLogFilePath , err )
185
- }
186
- fin .Close ()
187
- return nil
188
- }
189
-
190
160
for {
191
161
select {
192
162
case <- stopChannel :
193
- logrus .Debugf ("received stop signal, re-reading JSON logfile and returning" )
194
- // read final logs before returning
195
- return readFromLastPos ()
163
+ logrus .Debugf ("received stop signal while re-reading JSON logfile, returning" )
164
+ return nil
196
165
default :
197
- if err = readFromLastPos (); err != nil {
198
- return err
166
+ // Re-open the file and seek to the last-consumed offset.
167
+ fin , err = os .OpenFile (jsonLogFilePath , os .O_RDONLY , 0400 )
168
+ if err != nil {
169
+ fin .Close ()
170
+ return fmt .Errorf ("error occurred while trying to re-open JSON logfile %q: %s" , jsonLogFilePath , err )
199
171
}
172
+ _ , err = fin .Seek (lastPos , 0 )
173
+ if err != nil {
174
+ fin .Close ()
175
+ return fmt .Errorf ("error occurred while trying to seek JSON logfile %q at position %d: %s" , jsonLogFilePath , lastPos , err )
176
+ }
177
+
178
+ err = jsonfile .Decode (stdout , stderr , fin , lvopts .Timestamps , lvopts .Since , lvopts .Until , 0 )
179
+ if err != nil {
180
+ fin .Close ()
181
+ return fmt .Errorf ("error occurred while doing follow-up decoding of JSON logfile %q at starting position %d: %s" , jsonLogFilePath , lastPos , err )
182
+ }
183
+
184
+ // Record current file seek position before looping again.
185
+ lastPos , err = fin .Seek (0 , io .SeekCurrent )
186
+ if err != nil {
187
+ fin .Close ()
188
+ return fmt .Errorf ("error occurred while trying to seek JSON logfile %q at current position: %s" , jsonLogFilePath , err )
189
+ }
190
+ fin .Close ()
200
191
}
201
192
// Give the OS a second to breathe before re-opening the file:
202
193
time .Sleep (time .Second )
@@ -233,8 +224,6 @@ func viewLogsJSONFileThroughTailExec(lvopts LogViewOptions, jsonLogFilePath stri
233
224
// Setup killing goroutine:
234
225
go func () {
235
226
<- stopChannel
236
- // sleep 100ms to get logs post container exit
237
- time .Sleep (100 * time .Millisecond )
238
227
logrus .Debugf ("killing tail logs process with PID: %d" , cmd .Process .Pid )
239
228
cmd .Process .Kill ()
240
229
}()
0 commit comments