Skip to content

Commit

Permalink
Redirecting server logs to a file
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentganne committed Oct 23, 2018
1 parent 8f78979 commit 03b7dd7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commands/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func init() {
Run: func(cmd *cobra.Command, args []string) {
err := bootstrap()
if err != nil {
fmt.Print(err)
fmt.Println("Bootstrap error", err)
}
},
}
Expand Down
15 changes: 15 additions & 0 deletions commands/bootstrap/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"github.com/ystia/yorc/commands"
"github.com/ystia/yorc/config"
"github.com/ystia/yorc/log"
"io"
"io/ioutil"
"net/http"
Expand All @@ -39,6 +40,7 @@ import (

var cmdConsul *exec.Cmd
var yorcServerShutdownChan chan struct{}
var yorcServerOutputFile *os.File

// setupYorcServer starts a Yorc server
func setupYorcServer(workingDirectoryPath string) error {
Expand Down Expand Up @@ -91,8 +93,20 @@ func setupYorcServer(workingDirectoryPath string) error {
return err
}

// Yorc Server outputs rediected to a file
outputFileName := filepath.Join(workingDirectoryPath, "yorc.log")
yorcServerOutputFile, err := os.Create(outputFileName)
if err != nil {
return err
}

log.SetOutput(yorcServerOutputFile)

yorcServerShutdownChan = make(chan struct{})
err = commands.RunServer(yorcServerShutdownChan)
if err != nil {
yorcServerOutputFile.Close()
}
return err

}
Expand All @@ -103,6 +117,7 @@ func tearDownYorcServer(workingDirectoryPath string) error {
// Stop Yorc server
if yorcServerShutdownChan != nil {
close(yorcServerShutdownChan)
yorcServerOutputFile.Close()
}

// stop Consul
Expand Down

0 comments on commit 03b7dd7

Please sign in to comment.