diff --git a/libpod/container.go b/libpod/container.go index 1f5d2298a6..a6a509ae6c 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -669,6 +669,14 @@ func (c *Container) LogTag() string { return c.config.LogTag } +// LogSizeMax returns the maximum size of the container's log file. +func (c *Container) LogSizeMax() int64 { + if c.config.LogSize > 0 { + return c.config.LogSize + } + return c.runtime.config.Containers.LogSizeMax +} + // RestartPolicy returns the container's restart policy. func (c *Container) RestartPolicy() string { return c.config.RestartPolicy diff --git a/libpod/container_config.go b/libpod/container_config.go index 261158bf49..eaf2d8e907 100644 --- a/libpod/container_config.go +++ b/libpod/container_config.go @@ -378,7 +378,7 @@ type ContainerMiscConfig struct { LogPath string `json:"logPath"` // LogTag is the tag used for logging LogTag string `json:"logTag"` - // LogSize is the tag used for logging + // LogSize is the maximum size of the container's log file LogSize int64 `json:"logSize"` // LogDriver driver for logs LogDriver string `json:"logDriver"` diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go index e893d6fb3b..735d626abb 100644 --- a/libpod/container_inspect.go +++ b/libpod/container_inspect.go @@ -498,7 +498,7 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named logConfig := new(define.InspectLogConfig) logConfig.Type = c.config.LogDriver logConfig.Path = c.config.LogPath - logConfig.Size = units.HumanSize(float64(c.config.LogSize)) + logConfig.Size = units.HumanSize(float64(c.LogSizeMax())) logConfig.Tag = c.config.LogTag hostConfig.LogConfig = logConfig diff --git a/libpod/oci_conmon_common.go b/libpod/oci_conmon_common.go index 1b0f4c42da..02fecd21f1 100644 --- a/libpod/oci_conmon_common.go +++ b/libpod/oci_conmon_common.go @@ -1342,10 +1342,7 @@ func (r *ConmonOCIRuntime) sharedConmonArgs(ctr *Container, cuuid, bundlePath, p logrus.Debugf("%s messages will be logged to syslog", r.conmonPath) args = append(args, "--syslog") - size := r.logSizeMax - if ctr.config.LogSize > 0 { - size = ctr.config.LogSize - } + size := ctr.LogSizeMax() if size > 0 { args = append(args, "--log-size-max", strconv.FormatInt(size, 10)) } diff --git a/test/system/030-run.bats b/test/system/030-run.bats index 83c5f92eda..ce36b85ab0 100644 --- a/test/system/030-run.bats +++ b/test/system/030-run.bats @@ -1804,4 +1804,27 @@ RUN umount /etc/hostname; rm /etc/hostname run_podman rmi $randomname } +@test "podman run --log-opt size= and containers.conf log_size_max" { + skip_if_remote "remote does not support CONTAINERS_CONF" + + containersconf=$PODMAN_TMPDIR/containers.conf + cat >$containersconf <