diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2022-04-04 13:43:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-04 13:43:27 -0400 |
commit | 330205ebed7b4e196fbc20788440e409464e267a (patch) | |
tree | 700c5035410f351b7156ea447fa332e4edd06d3f /libpod/container_log.go | |
parent | 4f31ade2b251514992dec7cfe9444dd0c62f00b5 (diff) | |
parent | c185d8c0d6774e90f64f4c6a84270c20a9325944 (diff) | |
download | podman-330205ebed7b4e196fbc20788440e409464e267a.tar.gz podman-330205ebed7b4e196fbc20788440e409464e267a.tar.bz2 podman-330205ebed7b4e196fbc20788440e409464e267a.zip |
Merge pull request #13490 from gcalin/13266
pod logs enhancements: option to color logs
Diffstat (limited to 'libpod/container_log.go')
-rw-r--r-- | libpod/container_log.go | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/libpod/container_log.go b/libpod/container_log.go index dd5c36e26..7a9eb2dbf 100644 --- a/libpod/container_log.go +++ b/libpod/container_log.go @@ -23,8 +23,8 @@ func init() { // Log is a runtime function that can read one or more container logs. func (r *Runtime) Log(ctx context.Context, containers []*Container, options *logs.LogOptions, logChannel chan *logs.LogLine) error { - for _, ctr := range containers { - if err := ctr.ReadLog(ctx, options, logChannel); err != nil { + for c, ctr := range containers { + if err := ctr.ReadLog(ctx, options, logChannel, int64(c)); err != nil { return err } } @@ -32,26 +32,26 @@ func (r *Runtime) Log(ctx context.Context, containers []*Container, options *log } // ReadLog reads a containers log based on the input options and returns log lines over a channel. -func (c *Container) ReadLog(ctx context.Context, options *logs.LogOptions, logChannel chan *logs.LogLine) error { +func (c *Container) ReadLog(ctx context.Context, options *logs.LogOptions, logChannel chan *logs.LogLine, colorID int64) error { switch c.LogDriver() { case define.PassthroughLogging: return errors.Wrapf(define.ErrNoLogs, "this container is using the 'passthrough' log driver, cannot read logs") case define.NoLogging: return errors.Wrapf(define.ErrNoLogs, "this container is using the 'none' log driver, cannot read logs") case define.JournaldLogging: - return c.readFromJournal(ctx, options, logChannel) + return c.readFromJournal(ctx, options, logChannel, colorID) case define.JSONLogging: // TODO provide a separate implementation of this when Conmon // has support. fallthrough case define.KubernetesLogging, "": - return c.readFromLogFile(ctx, options, logChannel) + return c.readFromLogFile(ctx, options, logChannel, colorID) default: return errors.Wrapf(define.ErrInternal, "unrecognized log driver %q, cannot read logs", c.LogDriver()) } } -func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOptions, logChannel chan *logs.LogLine) error { +func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOptions, logChannel chan *logs.LogLine, colorID int64) error { t, tailLog, err := logs.GetLogFile(c.LogPath(), options) if err != nil { // If the log file does not exist, this is not fatal. @@ -65,6 +65,7 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption for _, nll := range tailLog { nll.CID = c.ID() nll.CName = c.Name() + nll.ColorID = colorID if nll.Since(options.Since) && nll.Until(options.Until) { logChannel <- nll } @@ -97,6 +98,7 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption } nll.CID = c.ID() nll.CName = c.Name() + nll.ColorID = colorID if nll.Since(options.Since) && nll.Until(options.Until) { logChannel <- nll } |