diff --git a/x/simulation/log.go b/x/simulation/log.go index d061bf1eeb..236a724407 100644 --- a/x/simulation/log.go +++ b/x/simulation/log.go @@ -35,6 +35,7 @@ func (lw *StandardLogWriter) AddEntry(opEntry OperationEntry) { // PrintLogs - print the logs to a simulation file func (lw *StandardLogWriter) PrintLogs() { f := createLogFile() + defer f.Close() for i := 0; i < len(lw.OpEntries); i++ { writeEntry := fmt.Sprintf("%s\n", (lw.OpEntries[i]).MustMarshal()) @@ -50,7 +51,7 @@ func createLogFile() *os.File { var f *os.File fileName := fmt.Sprintf("%s.log", time.Now().Format("2006-01-02_15:04:05")) - folderPath := os.ExpandEnv("$HOME/.simapp/simulations") + folderPath := path.Join(os.ExpandEnv("$HOME"), ".simapp", "simulations") filePath := path.Join(folderPath, fileName) err := os.MkdirAll(folderPath, os.ModePerm) @@ -58,7 +59,10 @@ func createLogFile() *os.File { panic(err) } - f, _ = os.Create(filePath) + f, err = os.Create(filePath) + if err != nil { + panic(err) + } fmt.Printf("Logs to writing to %s\n", filePath) return f