Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/api/handlers/compat/containers_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) {
}

if query.Timestamps {
frame.WriteString(line.Time.Format(time.RFC3339))
frame.WriteString(line.Time.Format(logs.LogTimeFormat))
frame.WriteString(" ")
}

Expand Down
12 changes: 12 additions & 0 deletions test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ like "$(<$WORKDIR/curl.headers.out)" ".*HTTP.* 200 OK.*" \

podman rm -f -t0 $CTRNAME

# verify API logs return timestamps with nanosecond precision
CTRNAME=timestamp-test
podman run --name $CTRNAME -d $IMAGE sh -c "echo test message"
podman wait $CTRNAME
t GET "containers/${CTRNAME}/logs?timestamps=true&stdout=true" 200
# /logs returns application/octet-stream with binary headers. Strip null bytes.
# Verify timestamp format includes nanoseconds (LogTimeFormat with 9 zero-padded digits)
# Timezone can be 'Z' (UTC) or '+/-HH:MM'
like "$(tr -d \\0 <$WORKDIR/curl.result.out)" ".*[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}T[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\.[0-9]\\{9\\}\\(Z\\|[+-][0-9]\\{2\\}:[0-9]\\{2\\}\\).*test message.*" \
"logs timestamps should include nanosecond precision"
podman rm -f $CTRNAME

CTRNAME=test123
podman run --name $CTRNAME -d $IMAGE top
t GET libpod/containers/$CTRNAME/top?ps_args=--invalid 500 \
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,29 @@ var _ = Describe("Podman logs", func() {
}).WithTimeout(logTimeout).Should(Succeed())
})

It("timestamps with nanosecond precision: "+log, func() {
skipIfJournaldInContainer()

logc := podmanTest.Podman([]string{"run", "--log-driver", log, "-dt", ALPINE, "echo", "test message"})
logc.WaitWithDefaultTimeout()
Expect(logc).To(ExitCleanly())
cid := logc.OutputToString()

wait := podmanTest.Podman([]string{"wait", cid})
wait.WaitWithDefaultTimeout()
Expect(wait).To(ExitCleanly())

Eventually(func(g Gomega) {
results := podmanTest.Podman([]string{"logs", "-t", cid})
results.WaitWithDefaultTimeout()
g.Expect(results).To(ExitCleanly())
// LogTimeFormat: 2006-01-02T15:04:05.000000000Z07:00
// Verify timestamp contains nanoseconds (exactly 9 digits, zero-padded)
// Timezone can be 'Z' (UTC) or '+/-HH:MM'
g.Expect(results.OutputToString()).To(MatchRegexp(`\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{9}(Z|[+-]\d{2}:\d{2})\s+test message`))
}).WithTimeout(logTimeout).Should(Succeed())
})

It("since time 2017-08-07: "+log, func() {
skipIfJournaldInContainer()

Expand Down