mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
Add no-trunc support to podman-events
Standardize on no-trunc through the code. Alias notruncate where necessary. Standardize on the man page display of no-trunc. Fixes: https://github.com/containers/podman/issues/8941 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/containers/storage/pkg/stringid"
|
||||
"github.com/hpcloud/tail"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -65,11 +66,15 @@ func (e *Event) ToJSONString() (string, error) {
|
||||
}
|
||||
|
||||
// ToHumanReadable returns human readable event as a formatted string
|
||||
func (e *Event) ToHumanReadable() string {
|
||||
func (e *Event) ToHumanReadable(truncate bool) string {
|
||||
var humanFormat string
|
||||
id := e.ID
|
||||
if truncate {
|
||||
id = stringid.TruncateID(id)
|
||||
}
|
||||
switch e.Type {
|
||||
case Container, Pod:
|
||||
humanFormat = fmt.Sprintf("%s %s %s %s (image=%s, name=%s", e.Time, e.Type, e.Status, e.ID, e.Image, e.Name)
|
||||
humanFormat = fmt.Sprintf("%s %s %s %s (image=%s, name=%s", e.Time, e.Type, e.Status, id, e.Image, e.Name)
|
||||
// check if the container has labels and add it to the output
|
||||
if len(e.Attributes) > 0 {
|
||||
for k, v := range e.Attributes {
|
||||
@ -78,9 +83,9 @@ func (e *Event) ToHumanReadable() string {
|
||||
}
|
||||
humanFormat += ")"
|
||||
case Network:
|
||||
humanFormat = fmt.Sprintf("%s %s %s %s (container=%s, name=%s)", e.Time, e.Type, e.Status, e.ID, e.ID, e.Network)
|
||||
humanFormat = fmt.Sprintf("%s %s %s %s (container=%s, name=%s)", e.Time, e.Type, e.Status, id, id, e.Network)
|
||||
case Image:
|
||||
humanFormat = fmt.Sprintf("%s %s %s %s %s", e.Time, e.Type, e.Status, e.ID, e.Name)
|
||||
humanFormat = fmt.Sprintf("%s %s %s %s %s", e.Time, e.Type, e.Status, id, e.Name)
|
||||
case System:
|
||||
humanFormat = fmt.Sprintf("%s %s %s", e.Time, e.Type, e.Status)
|
||||
case Volume:
|
||||
|
@ -63,7 +63,7 @@ func (e EventJournalD) Write(ee Event) error {
|
||||
case Volume:
|
||||
m["PODMAN_NAME"] = ee.Name
|
||||
}
|
||||
return journal.Send(string(ee.ToHumanReadable()), journal.PriInfo, m)
|
||||
return journal.Send(string(ee.ToHumanReadable(false)), journal.PriInfo, m)
|
||||
}
|
||||
|
||||
// Read reads events from the journal and sends qualified events to the event channel
|
||||
|
Reference in New Issue
Block a user