From 88a8d9e3fa19cf16b19716cb03fa457d98056010 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde <akasurde@redhat.com> Date: Tue, 18 Feb 2020 16:16:23 +0530 Subject: [WIP] Add cmd flag to show container name in log This flag allows user to show container name in podman log command Fixes: #4962 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> --- cmd/podman/cliconfig/config.go | 1 + cmd/podman/logs.go | 3 +++ 2 files changed, 4 insertions(+) (limited to 'cmd') diff --git a/cmd/podman/cliconfig/config.go b/cmd/podman/cliconfig/config.go index 6bc8aa4a3..d9b42b99f 100644 --- a/cmd/podman/cliconfig/config.go +++ b/cmd/podman/cliconfig/config.go @@ -260,6 +260,7 @@ type LogsValues struct { Tail int64 Timestamps bool Latest bool + UseNames bool } type MountValues struct { diff --git a/cmd/podman/logs.go b/cmd/podman/logs.go index a2594b5bf..291347adb 100644 --- a/cmd/podman/logs.go +++ b/cmd/podman/logs.go @@ -37,6 +37,7 @@ var ( return nil }, Example: `podman logs ctrID + podman logs --names ctrID1 ctrID2 podman logs --tail 2 mywebserver podman logs --follow=true --since 10m ctrID podman logs mywebserver mydbserver`, @@ -54,6 +55,7 @@ func init() { flags.StringVar(&logsCommand.Since, "since", "", "Show logs since TIMESTAMP") flags.Int64Var(&logsCommand.Tail, "tail", -1, "Output the specified number of LINES at the end of the logs. Defaults to -1, which prints all lines") flags.BoolVarP(&logsCommand.Timestamps, "timestamps", "t", false, "Output the timestamps in the log") + flags.BoolVarP(&logsCommand.UseNames, "names", "n", false, "Output the container name in the log") markFlagHidden(flags, "details") flags.SetInterspersed(false) @@ -85,6 +87,7 @@ func logsCmd(c *cliconfig.LogsValues) error { Since: sinceTime, Tail: c.Tail, Timestamps: c.Timestamps, + UseNames: c.UseNames, } return runtime.Log(c, options) } -- cgit v1.2.3-54-g00ecf From 7f411cb325986e88f1b04c2fc2a0e17a9e283ddf Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde <akasurde@redhat.com> Date: Wed, 19 Feb 2020 17:14:20 +0530 Subject: Review comments Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> --- cmd/podman/cliconfig/config.go | 2 +- cmd/podman/logs.go | 4 ++-- libpod/logs/log.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/cliconfig/config.go b/cmd/podman/cliconfig/config.go index d9b42b99f..ccc30c603 100644 --- a/cmd/podman/cliconfig/config.go +++ b/cmd/podman/cliconfig/config.go @@ -260,7 +260,7 @@ type LogsValues struct { Tail int64 Timestamps bool Latest bool - UseNames bool + UseName bool } type MountValues struct { diff --git a/cmd/podman/logs.go b/cmd/podman/logs.go index 291347adb..4bb26cd07 100644 --- a/cmd/podman/logs.go +++ b/cmd/podman/logs.go @@ -55,7 +55,7 @@ func init() { flags.StringVar(&logsCommand.Since, "since", "", "Show logs since TIMESTAMP") flags.Int64Var(&logsCommand.Tail, "tail", -1, "Output the specified number of LINES at the end of the logs. Defaults to -1, which prints all lines") flags.BoolVarP(&logsCommand.Timestamps, "timestamps", "t", false, "Output the timestamps in the log") - flags.BoolVarP(&logsCommand.UseNames, "names", "n", false, "Output the container name in the log") + flags.BoolVarP(&logsCommand.UseName, "names", "n", false, "Output the container name in the log") markFlagHidden(flags, "details") flags.SetInterspersed(false) @@ -87,7 +87,7 @@ func logsCmd(c *cliconfig.LogsValues) error { Since: sinceTime, Tail: c.Tail, Timestamps: c.Timestamps, - UseNames: c.UseNames, + UseName: c.UseName, } return runtime.Log(c, options) } diff --git a/libpod/logs/log.go b/libpod/logs/log.go index 180b3f14b..c2ce1e426 100644 --- a/libpod/logs/log.go +++ b/libpod/logs/log.go @@ -35,7 +35,7 @@ type LogOptions struct { Timestamps bool Multi bool WaitGroup *sync.WaitGroup - UseNames bool + UseName bool } // LogLine describes the information for each line of a log @@ -122,7 +122,7 @@ func getTailLog(path string, tail int) ([]*LogLine, error) { func (l *LogLine) String(options *LogOptions) string { var out string if options.Multi { - if options.UseNames { + if options.UseName { cname := l.CName out = fmt.Sprintf("%s ", cname) } else { -- cgit v1.2.3-54-g00ecf