summaryrefslogtreecommitdiff
path: root/libpod/logs/log.go
diff options
context:
space:
mode:
authorAbhijeet Kasurde <akasurde@redhat.com>2020-02-18 16:16:23 +0530
committerAbhijeet Kasurde <akasurde@redhat.com>2020-02-19 16:58:04 +0530
commit88a8d9e3fa19cf16b19716cb03fa457d98056010 (patch)
treef59c42ca52c97008ec2068dbfbebbf40ec1249cf /libpod/logs/log.go
parent0bd29f89e9d26c9012c76e58050e1bdfd90faaf0 (diff)
downloadpodman-88a8d9e3fa19cf16b19716cb03fa457d98056010.tar.gz
podman-88a8d9e3fa19cf16b19716cb03fa457d98056010.tar.bz2
podman-88a8d9e3fa19cf16b19716cb03fa457d98056010.zip
[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>
Diffstat (limited to 'libpod/logs/log.go')
-rw-r--r--libpod/logs/log.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/libpod/logs/log.go b/libpod/logs/log.go
index 9a7bcb5be..180b3f14b 100644
--- a/libpod/logs/log.go
+++ b/libpod/logs/log.go
@@ -35,6 +35,7 @@ type LogOptions struct {
Timestamps bool
Multi bool
WaitGroup *sync.WaitGroup
+ UseNames bool
}
// LogLine describes the information for each line of a log
@@ -44,6 +45,7 @@ type LogLine struct {
Time time.Time
Msg string
CID string
+ CName string
}
// GetLogFile returns an hp tail for a container given options
@@ -120,11 +122,16 @@ func getTailLog(path string, tail int) ([]*LogLine, error) {
func (l *LogLine) String(options *LogOptions) string {
var out string
if options.Multi {
- cid := l.CID
- if len(cid) > 12 {
- cid = cid[:12]
+ if options.UseNames {
+ cname := l.CName
+ out = fmt.Sprintf("%s ", cname)
+ } else {
+ cid := l.CID
+ if len(cid) > 12 {
+ cid = cid[:12]
+ }
+ out = fmt.Sprintf("%s ", cid)
}
- out = fmt.Sprintf("%s ", cid)
}
if options.Timestamps {
out += fmt.Sprintf("%s ", l.Time.Format(LogTimeFormat))