Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
logging: Reset external loggers when cid+sid available
Browse files Browse the repository at this point in the history
Once `containerID` and `sandboxID` fields are available, re-register
the logger with the external packages to ensure they too display these
important fields.

Fixes #467.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel authored and Eric Ernst committed Aug 23, 2018
1 parent 371dc14 commit 9774c2a
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func create(containerID, bundlePath, console, pidFilePath string, detach bool,
var err error

kataLog = kataLog.WithField("container", containerID)
setExternalLoggers(kataLog)

// Checks the MUST and MUST NOT from OCI runtime specification
if bundlePath, err = validCreateParams(containerID, bundlePath); err != nil {
Expand Down Expand Up @@ -240,6 +241,7 @@ func createSandbox(ociSpec oci.CompatOCISpec, runtimeConfig oci.RuntimeConfig,
}

kataLog = kataLog.WithField("sandbox", sandbox.ID())
setExternalLoggers(kataLog)

containers := sandbox.GetAllContainers()
if len(containers) != 1 {
Expand Down Expand Up @@ -267,6 +269,7 @@ func createContainer(ociSpec oci.CompatOCISpec, containerID, bundlePath,
}

kataLog = kataLog.WithField("sandbox", sandboxID)
setExternalLoggers(kataLog)

_, c, err := vci.CreateContainer(sandboxID, contConfig)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func delete(containerID string, force bool) error {
"sandbox": sandboxID,
})

setExternalLoggers(kataLog)

containerID = status.ID

containerType, err := oci.GetContainerType(status.Annotations)
Expand Down
2 changes: 2 additions & 0 deletions cli/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ information is displayed once every 5 seconds.`,
"sandbox": sandboxID,
})

setExternalLoggers(kataLog)

if status.State.State == vc.StateStopped {
return fmt.Errorf("container with id %s is not running", status.ID)
}
Expand Down
2 changes: 2 additions & 0 deletions cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ func execute(context *cli.Context) error {
"sandbox": sandboxID,
})

setExternalLoggers(kataLog)

// Retrieve OCI spec configuration.
ociSpec, err := oci.GetOCIConfig(status)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cli/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ func kill(containerID, signal string, all bool) error {
"sandbox": sandboxID,
})

setExternalLoggers(kataLog)

signum, err := processSignal(signal)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions cli/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func toggleContainerPause(containerID string, pause bool) (err error) {
"sandbox": sandboxID,
})

setExternalLoggers(kataLog)

if pause {
err = vci.PauseContainer(sandboxID, containerID)
} else {
Expand Down
2 changes: 2 additions & 0 deletions cli/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func ps(containerID, format string, args []string) error {
"sandbox": sandboxID,
})

setExternalLoggers(kataLog)

// container MUST be running
if status.State.State != vc.StateRunning {
return fmt.Errorf("Container %s is not running", containerID)
Expand Down
2 changes: 2 additions & 0 deletions cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func start(containerID string) (vc.VCSandbox, error) {
"sandbox": sandboxID,
})

setExternalLoggers(kataLog)

containerID = status.ID

containerType, err := oci.GetContainerType(status.Annotations)
Expand Down
2 changes: 2 additions & 0 deletions cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ instance of a container.`,
func state(containerID string) error {
kataLog = kataLog.WithField("container", containerID)

setExternalLoggers(kataLog)

// Checks the MUST and MUST NOT from OCI runtime specification
status, _, err := getExistingContainerInfo(containerID)
if err != nil {
Expand Down

0 comments on commit 9774c2a

Please sign in to comment.