From the first glance, `docker logs --tail 0` does not make sense,
as it is supposed to produce no output, but `tail -n 0` from GNU
coreutils is working like that, plus there is even a test case
(`TestLogsTail` in integration-cli/docker_cli_logs_test.go).
Now, something like `docker logs --follow --tail 0` makes total
sense, so let's make it work.
(NOTE if --tail is not used, config.Tail is set to -1)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit dd4bfe30a8ac1b31630310090dc36ae3d9253444)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
| ... | ... |
@@ -332,7 +332,7 @@ func (s *journald) readLogs(logWatcher *logger.LogWatcher, config logger.ReadCon |
| 332 | 332 |
nano := config.Until.UnixNano() |
| 333 | 333 |
untilUnixMicro = uint64(nano / 1000) |
| 334 | 334 |
} |
| 335 |
- if config.Tail > 0 {
|
|
| 335 |
+ if config.Tail >= 0 {
|
|
| 336 | 336 |
// If until time provided, start from there. |
| 337 | 337 |
// Otherwise start at the end of the journal. |
| 338 | 338 |
if untilUnixMicro != 0 && C.sd_journal_seek_realtime_usec(j, C.uint64_t(untilUnixMicro)) < 0 {
|
| ... | ... |
@@ -343,7 +343,7 @@ func (s *journald) readLogs(logWatcher *logger.LogWatcher, config logger.ReadCon |
| 343 | 343 |
return |
| 344 | 344 |
} |
| 345 | 345 |
// (Try to) skip backwards by the requested number of lines... |
| 346 |
- if C.sd_journal_previous_skip(j, C.uint64_t(config.Tail)) > 0 {
|
|
| 346 |
+ if C.sd_journal_previous_skip(j, C.uint64_t(config.Tail)) >= 0 {
|
|
| 347 | 347 |
// ...but not before "since" |
| 348 | 348 |
if sinceUnixMicro != 0 && |
| 349 | 349 |
C.sd_journal_get_realtime_usec(j, &stamp) == 0 && |
| ... | ... |
@@ -367,7 +367,9 @@ func (s *journald) readLogs(logWatcher *logger.LogWatcher, config logger.ReadCon |
| 367 | 367 |
return |
| 368 | 368 |
} |
| 369 | 369 |
} |
| 370 |
- cursor, _, _ = s.drainJournal(logWatcher, j, nil, untilUnixMicro) |
|
| 370 |
+ if config.Tail != 0 { // special case for --tail 0
|
|
| 371 |
+ cursor, _, _ = s.drainJournal(logWatcher, j, nil, untilUnixMicro) |
|
| 372 |
+ } |
|
| 371 | 373 |
if config.Follow {
|
| 372 | 374 |
cursor = s.followJournal(logWatcher, j, cursor, untilUnixMicro) |
| 373 | 375 |
// Let followJournal handle freeing the journal context |