Skip to content

Commit

Permalink
Merge pull request #57 from asalkeld/unique-log-file
Browse files Browse the repository at this point in the history
Make the run log file unique
  • Loading branch information
tjholm authored Feb 3, 2022
2 parents 726004d + 81808b9 commit 4408494
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/containerengine/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"io"
"log"
"os/exec"
"path"
"strings"
"time"

Expand Down Expand Up @@ -291,6 +290,7 @@ func (d *docker) Logger(stackPath string) ContainerLogger {
if d.logger != nil {
return d.logger
}
d.logger = newSyslog(path.Join(utils.NitricLogDir(stackPath), "run.log"))
logPath, _ := utils.NewNitricLogFile(stackPath)
d.logger = newSyslog(logPath)
return d.logger
}
4 changes: 2 additions & 2 deletions pkg/containerengine/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"io"
"os/exec"
"path"
"strings"
"time"

Expand Down Expand Up @@ -131,7 +130,8 @@ func (p *podman) ContainerExec(containerName string, cmd []string, workingDir st
}

func (p *podman) Logger(stackPath string) ContainerLogger {
return &jsonfile{logPath: path.Join(utils.NitricLogDir(stackPath), "run.log")}
logPath, _ := utils.NewNitricLogFile(stackPath)
return &jsonfile{logPath: logPath}
}

type jsonfile struct {
Expand Down
4 changes: 3 additions & 1 deletion pkg/run/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
Expand Down Expand Up @@ -126,7 +127,8 @@ func (m *MinioServer) GetApiPort() int {
}

func (m *MinioServer) Stop() error {
return m.ce.Stop(m.cid, nil)
timeout := time.Second * 5
return m.ce.Stop(m.cid, &timeout)
}

func NewMinio(dir string, name string) (*MinioServer, error) {
Expand Down
10 changes: 10 additions & 0 deletions pkg/utils/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ func NitricConfigDir() string {
func NitricLogDir(stackPath string) string {
return path.Join(stackPath, ".nitric")
}

// NewNitricLogFile returns a path to a unique log file that does not exist.
func NewNitricLogFile(stackPath string) (string, error) {
tf, err := os.CreateTemp(NitricLogDir(stackPath), "run-*.log")
if err != nil {
return "", err
}
tf.Close()
return tf.Name(), nil
}

0 comments on commit 4408494

Please sign in to comment.