Skip to content

Commit

Permalink
simulation: close opened files and check for error while creating fil…
Browse files Browse the repository at this point in the history
…es (#8217)

* Read gentx amount as argument

* Update gentx command usage

* Update gentx tests

* Update docs of gentx

* Close opened files and check for error while creating files

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Anil Kumar Kammari <anil@vitwit.com>
  • Loading branch information
3 people authored Dec 22, 2020
1 parent c82febe commit f9dc082
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions x/simulation/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -50,15 +51,18 @@ 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)
if err != nil {
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
Expand Down

0 comments on commit f9dc082

Please sign in to comment.