mirror of
https://github.com/containers/podman.git
synced 2025-10-18 19:53:58 +08:00
Added --log-driver and journald logging
Signed-off-by: Peter Hunt <pehunt@redhat.com>
This commit is contained in:
@ -631,6 +631,10 @@ func GetCtrInspectInfo(config *libpod.ContainerConfig, ctrInspectData *inspect.C
|
||||
memKernel, memReservation, memSwap, memSwappiness, memDisableOOMKiller := getMemoryInfo(spec)
|
||||
pidsLimit := getPidsInfo(spec)
|
||||
cgroup := getCgroup(spec)
|
||||
logConfig := inspect.LogConfig{
|
||||
config.LogDriver,
|
||||
make(map[string]string),
|
||||
}
|
||||
|
||||
data := &inspect.ContainerData{
|
||||
ctrInspectData,
|
||||
@ -681,6 +685,7 @@ func GetCtrInspectInfo(config *libpod.ContainerConfig, ctrInspectData *inspect.C
|
||||
Ulimits: createArtifact.Resources.Ulimit,
|
||||
SecurityOpt: createArtifact.SecurityOpts,
|
||||
Tmpfs: createArtifact.Tmpfs,
|
||||
LogConfig: &logConfig,
|
||||
},
|
||||
&inspect.CtrConfig{
|
||||
Hostname: spec.Hostname,
|
||||
|
@ -603,6 +603,11 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
|
||||
|
||||
memorySwappiness := c.Int64("memory-swappiness")
|
||||
|
||||
logDriver := "k8s-file"
|
||||
if c.Changed("log-driver") {
|
||||
logDriver = c.String("log-driver")
|
||||
}
|
||||
|
||||
config := &cc.CreateConfig{
|
||||
Annotations: annotations,
|
||||
BuiltinImgVolumes: ImageVolumes,
|
||||
@ -635,7 +640,7 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
|
||||
IPAddress: c.String("ip"),
|
||||
Labels: labels,
|
||||
//LinkLocalIP: c.StringSlice("link-local-ip"), // Not implemented yet
|
||||
LogDriver: c.String("log-driver"),
|
||||
LogDriver: logDriver,
|
||||
LogDriverOpt: c.StringSlice("log-opt"),
|
||||
MacAddress: c.String("mac-address"),
|
||||
Name: c.String("name"),
|
||||
|
@ -486,7 +486,7 @@ __podman_complete_log_drivers() {
|
||||
none
|
||||
splunk
|
||||
syslog
|
||||
k8s-file
|
||||
k8s-file
|
||||
" -- "$cur" ) )
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ type CtrConfig struct {
|
||||
|
||||
// LogConfig holds the log information for a container
|
||||
type LogConfig struct {
|
||||
Type string `json:"Type"` // TODO
|
||||
Type string `json:"Type"`
|
||||
Config map[string]string `json:"Config"` //idk type, TODO
|
||||
}
|
||||
|
||||
|
@ -319,6 +319,9 @@ func (c *CreateConfig) getContainerCreateOptions(runtime *libpod.Runtime, pod *l
|
||||
if logPath != "" {
|
||||
options = append(options, libpod.WithLogPath(logPath))
|
||||
}
|
||||
|
||||
options = append(options, libpod.WithLogDriver(c.LogDriver))
|
||||
|
||||
if c.IPAddress != "" {
|
||||
ip := net.ParseIP(c.IPAddress)
|
||||
if ip == nil {
|
||||
|
Reference in New Issue
Block a user