diff --git a/cmd/podman/pods/logs.go b/cmd/podman/pods/logs.go index 1b00f047ee29..e35b48bed0be 100644 --- a/cmd/podman/pods/logs.go +++ b/cmd/podman/pods/logs.go @@ -87,6 +87,7 @@ func logsFlags(cmd *cobra.Command) { flags.Int64Var(&logsPodOptions.Tail, tailFlagName, -1, "Output the specified number of LINES at the end of the logs.") _ = cmd.RegisterFlagCompletionFunc(tailFlagName, completion.AutocompleteNone) + flags.BoolVarP(&logsPodOptions.Names, "names", "n", false, "Output container names instead of container IDs in the log") flags.BoolVarP(&logsPodOptions.Timestamps, "timestamps", "t", false, "Output the timestamps in the log") flags.SetInterspersed(false) _ = flags.MarkHidden("details") diff --git a/docs/source/markdown/podman-pod-logs.1.md b/docs/source/markdown/podman-pod-logs.1.md index 53aa5d58b3c8..961447197cc1 100644 --- a/docs/source/markdown/podman-pod-logs.1.md +++ b/docs/source/markdown/podman-pod-logs.1.md @@ -28,6 +28,10 @@ chance that the log file will be removed before `podman pod logs` reads the fina Instead of providing the pod name or id, get logs of the last created pod. (This option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines) +#### **--names**, **-n** + +Output the container names instead of the container IDs in the log + #### **--since**=*TIMESTAMP* Show logs since TIMESTAMP. The --since option can be Unix timestamps, date formatted timestamps, or Go duration diff --git a/test/e2e/logs_test.go b/test/e2e/logs_test.go index 7c0fcc8ee293..6330066fd4fa 100644 --- a/test/e2e/logs_test.go +++ b/test/e2e/logs_test.go @@ -37,7 +37,9 @@ var _ = Describe("Podman logs", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() + if err := podmanTest.SeedImages(); err != nil { + os.Exit(1) + } }) AfterEach(func() { @@ -412,4 +414,31 @@ var _ = Describe("Podman logs", func() { logs.WaitWithDefaultTimeout() Expect(logs).To(Not(Exit(0))) }) + + FIt("podman pod logs with container names", func() { + podName := "test-pod" + containerName1 := "container-1" + containerName2 := "container-2" + + testPod := podmanTest.Podman([]string{"pod", "create", fmt.Sprintf("--name=%s", podName)}) + testPod.WaitWithDefaultTimeout() + Expect(testPod).To(Exit(0)) + + log1 := podmanTest.Podman([]string{"run", "--name", containerName1, "-d", "--pod", podName, BB, "/bin/sh", "-c", "echo podman"}) + log1.WaitWithDefaultTimeout() + Expect(log1).To(Exit(0)) + + log2 := podmanTest.Podman([]string{"run", "--name", containerName2, "-d", "--pod", podName, BB, "/bin/sh", "-c", "echo podman"}) + log2.WaitWithDefaultTimeout() + Expect(log2).To(Exit(0)) + + results := podmanTest.Podman([]string{"pod", "logs", "--names", podName}) + results.WaitWithDefaultTimeout() + Expect(results).To(Exit(0)) + + output := results.OutputToStringArray() + Expect(output).To(HaveLen(2)) + Expect(output).To(ContainElement(ContainSubstring(containerName1))) + Expect(output).To(ContainElement(ContainSubstring(containerName2))) + }) })