summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-02-28 18:55:58 +0100
committerGitHub <noreply@github.com>2020-02-28 18:55:58 +0100
commita58bf77d3eb31b48fd8904b782543e3fe364df66 (patch)
tree4b24e15baceda19e57de1a3345a23b576f4741a5 /libpod
parentc19269639359e24be9a50143faac47b473522c91 (diff)
parent7f411cb325986e88f1b04c2fc2a0e17a9e283ddf (diff)
downloadpodman-a58bf77d3eb31b48fd8904b782543e3fe364df66.tar.gz
podman-a58bf77d3eb31b48fd8904b782543e3fe364df66.tar.bz2
podman-a58bf77d3eb31b48fd8904b782543e3fe364df66.zip
Merge pull request #5244 from Akasurde/i4962
Add cmd flag to show container name in log
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container.log.go2
-rw-r--r--libpod/logs/log.go15
2 files changed, 13 insertions, 4 deletions
diff --git a/libpod/container.log.go b/libpod/container.log.go
index 7c46dde9a..514edb8c8 100644
--- a/libpod/container.log.go
+++ b/libpod/container.log.go
@@ -41,6 +41,7 @@ func (c *Container) readFromLogFile(options *logs.LogOptions, logChannel chan *l
if len(tailLog) > 0 {
for _, nll := range tailLog {
nll.CID = c.ID()
+ nll.CName = c.Name()
if nll.Since(options.Since) {
logChannel <- nll
}
@@ -63,6 +64,7 @@ func (c *Container) readFromLogFile(options *logs.LogOptions, logChannel chan *l
partial = ""
}
nll.CID = c.ID()
+ nll.CName = c.Name()
if nll.Since(options.Since) {
logChannel <- nll
}
diff --git a/libpod/logs/log.go b/libpod/logs/log.go
index bd918abae..200ef3e99 100644
--- a/libpod/logs/log.go
+++ b/libpod/logs/log.go
@@ -38,6 +38,7 @@ type LogOptions struct {
Timestamps bool
Multi bool
WaitGroup *sync.WaitGroup
+ UseName bool
}
// LogLine describes the information for each line of a log
@@ -47,6 +48,7 @@ type LogLine struct {
Time time.Time
Msg string
CID string
+ CName string
}
// GetLogFile returns an hp tail for a container given options
@@ -164,11 +166,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.UseName {
+ 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))