mirror of
https://github.com/containers/podman.git
synced 2025-06-26 12:56:45 +08:00
Merge pull request #7232 from Luap99/podman-logs-tail
fix podman logs --tail when log is bigger than pagesize
This commit is contained in:
@ -101,11 +101,14 @@ func getTailLog(path string, tail int) ([]*LogLine, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Cause(err) == io.EOF {
|
if errors.Cause(err) == io.EOF {
|
||||||
inputs <- []string{leftover}
|
inputs <- []string{leftover}
|
||||||
close(inputs)
|
} else {
|
||||||
break
|
|
||||||
}
|
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
|
}
|
||||||
close(inputs)
|
close(inputs)
|
||||||
|
if err := f.Close(); err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
line := strings.Split(s+leftover, "\n")
|
line := strings.Split(s+leftover, "\n")
|
||||||
if len(line) > 1 {
|
if len(line) > 1 {
|
||||||
@ -136,9 +139,6 @@ func getTailLog(path string, tail int) ([]*LogLine, error) {
|
|||||||
}
|
}
|
||||||
// if we have enough loglines, we can hangup
|
// if we have enough loglines, we can hangup
|
||||||
if nllCounter >= tail {
|
if nllCounter >= tail {
|
||||||
if err := f.Close(); err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ func (r *ReverseReader) Read() (string, error) {
|
|||||||
if int64(n) < r.readSize {
|
if int64(n) < r.readSize {
|
||||||
b = b[0:n]
|
b = b[0:n]
|
||||||
}
|
}
|
||||||
// Set to the next page boundary
|
// Move the offset one pagesize up
|
||||||
r.offset = -r.readSize
|
r.offset -= r.readSize
|
||||||
return string(b), nil
|
return string(b), nil
|
||||||
}
|
}
|
||||||
|
@ -72,16 +72,16 @@ var _ = Describe("Podman logs", func() {
|
|||||||
Expect(len(results.OutputToStringArray())).To(Equal(0))
|
Expect(len(results.OutputToStringArray())).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("tail 99 lines", func() {
|
It("tail 800 lines", func() {
|
||||||
logc := podmanTest.Podman([]string{"run", "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"})
|
logc := podmanTest.Podman([]string{"run", "-dt", ALPINE, "sh", "-c", "i=1; while [ \"$i\" -ne 1000 ]; do echo \"line $i\"; i=$((i + 1)); done"})
|
||||||
logc.WaitWithDefaultTimeout()
|
logc.WaitWithDefaultTimeout()
|
||||||
Expect(logc).To(Exit(0))
|
Expect(logc).To(Exit(0))
|
||||||
cid := logc.OutputToString()
|
cid := logc.OutputToString()
|
||||||
|
|
||||||
results := podmanTest.Podman([]string{"logs", "--tail", "99", cid})
|
results := podmanTest.Podman([]string{"logs", "--tail", "800", cid})
|
||||||
results.WaitWithDefaultTimeout()
|
results.WaitWithDefaultTimeout()
|
||||||
Expect(results).To(Exit(0))
|
Expect(results).To(Exit(0))
|
||||||
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
Expect(len(results.OutputToStringArray())).To(Equal(800))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("tail 2 lines with timestamps", func() {
|
It("tail 2 lines with timestamps", func() {
|
||||||
|
Reference in New Issue
Block a user