diff --git a/core/logs.go b/core/logs.go index e94c4239e..b7bd6233b 100644 --- a/core/logs.go +++ b/core/logs.go @@ -233,9 +233,20 @@ func (ds *dockerService) createCRIFormattedContainerLog(containerID string) erro return fmt.Errorf("failed to get container %q log path: %v", containerID, err) } + if kubePath == "" { + logrus.Debugf("Container log path for Container ID %s isn't specified, will not create kubepath", containerID) + return nil + } + logrus.Infof("Creating CRI formatted container log at %s", kubePath) go func() { + _, err = os.Create(kubePath) + if err != nil { + logrus.Infof("Failed to create kube log file %s: %v", kubePath, err) + panic(err) + } + // Open the kube file for output kubeFile, err := os.OpenFile(kubePath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) if err != nil { @@ -245,12 +256,11 @@ func (ds *dockerService) createCRIFormattedContainerLog(containerID string) erro defer kubeFile.Close() // Make sure the docker file exists - dockerFile, err := os.Create(dockerPath) + _, err = os.Create(dockerPath) if err != nil { logrus.Infof("Failed to create docker log file %s: %v", dockerPath, err) panic(err) } - defer dockerFile.Close() // Tail the docker file for input t, err := tail.TailFile(dockerPath, tail.Config{