diff options
author | Peter Hunt <pehunt@redhat.com> | 2019-05-18 19:39:11 -0400 |
---|---|---|
committer | Peter Hunt <pehunt@redhat.com> | 2019-05-28 11:10:57 -0400 |
commit | f61fa28d39298def261dded2644b8dcf45366415 (patch) | |
tree | 36081cf2a2644264099ffcf32836b8c85f9ddb04 /libpod | |
parent | 18d7fcb5eb1966c4d3748a50c625c01c1ebd9f5b (diff) | |
download | podman-f61fa28d39298def261dded2644b8dcf45366415.tar.gz podman-f61fa28d39298def261dded2644b8dcf45366415.tar.bz2 podman-f61fa28d39298def261dded2644b8dcf45366415.zip |
Added --log-driver and journald logging
Signed-off-by: Peter Hunt <pehunt@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container.go | 7 | ||||
-rw-r--r-- | libpod/container_log.go | 5 | ||||
-rw-r--r-- | libpod/oci.go | 5 | ||||
-rw-r--r-- | libpod/oci_linux.go | 8 | ||||
-rw-r--r-- | libpod/options.go | 19 | ||||
-rw-r--r-- | libpod/runtime_ctr.go | 3 |
6 files changed, 42 insertions, 5 deletions
diff --git a/libpod/container.go b/libpod/container.go index c07f4c78d..9ac08cba0 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -368,6 +368,8 @@ type ContainerConfig struct { CgroupParent string `json:"cgroupParent"` // LogPath log location LogPath string `json:"logPath"` + // LogDriver driver for logs + LogDriver string `json:"logDriver"` // File containing the conmon PID ConmonPidFile string `json:"conmonPidFile,omitempty"` // RestartPolicy indicates what action the container will take upon @@ -775,6 +777,11 @@ func (c *Container) RestartRetries() uint { return c.config.RestartRetries } +// LogDriver returns the log driver for this container +func (c *Container) LogDriver() string { + return c.config.LogDriver +} + // RuntimeName returns the name of the runtime func (c *Container) RuntimeName() string { return c.runtime.ociRuntime.name diff --git a/libpod/container_log.go b/libpod/container_log.go index e998ad316..f11db8014 100644 --- a/libpod/container_log.go +++ b/libpod/container_log.go @@ -53,6 +53,11 @@ func (r *Runtime) Log(containers []*Container, options *LogOptions, logChannel c // ReadLog reads a containers log based on the input options and returns loglines over a channel func (c *Container) ReadLog(options *LogOptions, logChannel chan *LogLine) error { + // TODO Skip sending logs until journald logs can be read + // TODO make this not a magic string + if c.LogDriver() == "journald" { + return ErrNotImplemented + } t, tailLog, err := getLogFile(c.LogPath(), options) if err != nil { // If the log file does not exist, this is not fatal. diff --git a/libpod/oci.go b/libpod/oci.go index abc6214b9..152c8e73e 100644 --- a/libpod/oci.go +++ b/libpod/oci.go @@ -367,8 +367,6 @@ func (r *OCIRuntime) execContainer(c *Container, cmd, capAdd, env []string, tty args := []string{} // TODO - should we maintain separate logpaths for exec sessions? - args = append(args, "--log", c.LogPath()) - args = append(args, "exec") if cwd != "" { @@ -402,9 +400,10 @@ func (r *OCIRuntime) execContainer(c *Container, cmd, capAdd, env []string, tty args = append(args, "--env", envVar) } - // Append container ID and command + // Append container ID, name and command args = append(args, c.ID()) args = append(args, cmd...) + args = append(args, c.Name()) logrus.Debugf("Starting runtime %s with following arguments: %v", r.path, args) diff --git a/libpod/oci_linux.go b/libpod/oci_linux.go index 1c1e4a203..b3a21948e 100644 --- a/libpod/oci_linux.go +++ b/libpod/oci_linux.go @@ -217,7 +217,6 @@ func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string, res args = append(args, "-r", r.path) args = append(args, "-b", ctr.bundlePath()) args = append(args, "-p", filepath.Join(ctr.state.RunDir, "pidfile")) - args = append(args, "-l", ctr.LogPath()) args = append(args, "--exit-dir", r.exitsDir) if ctr.config.ConmonPidFile != "" { args = append(args, "--conmon-pidfile", ctr.config.ConmonPidFile) @@ -237,6 +236,13 @@ func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string, res if r.logSizeMax >= 0 { args = append(args, "--log-size-max", fmt.Sprintf("%v", r.logSizeMax)) } + + logDriver := "k8s-file" + if ctr.LogDriver() != "" { + logDriver = ctr.LogDriver() + } + args = append(args, "-l", fmt.Sprintf("%s:%s", logDriver, ctr.LogPath())) + if r.noPivot { args = append(args, "--no-pivot") } diff --git a/libpod/options.go b/libpod/options.go index 7ec7dfe63..d6eb97609 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -979,6 +979,25 @@ func WithStaticIP(ip net.IP) CtrCreateOption { } } +// WithLogDriver sets the log driver for the container +func WithLogDriver(driver string) CtrCreateOption { + return func(ctr *Container) error { + if ctr.valid { + return ErrCtrFinalized + } + if driver == "" { + return errors.Wrapf(ErrInvalidArg, "log driver must be set") + } + if driver != "journald" && driver != "k8s-file" && driver != "json-file" { + return errors.Wrapf(ErrInvalidArg, "invalid log driver") + } + + ctr.config.LogDriver = driver + + return nil + } +} + // WithLogPath sets the path to the log file. func WithLogPath(path string) CtrCreateOption { return func(ctr *Container) error { diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index c7758055f..25db10d33 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -196,7 +196,8 @@ func (r *Runtime) newContainer(ctx context.Context, rSpec *spec.Spec, options .. } } - if ctr.config.LogPath == "" { + // TODO magic string + if ctr.config.LogPath == "" && ctr.config.LogDriver != "journald" { ctr.config.LogPath = filepath.Join(ctr.config.StaticDir, "ctr.log") } |