Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launchpad: simulation: close open files, fix error checks #8226

Merged
merged 1 commit into from
Feb 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions x/simulation/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ 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())
_, err := f.WriteString(writeEntry)
Expand All @@ -45,17 +47,22 @@ func (lw *StandardLogWriter) PrintLogs() {

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")
fileName := fmt.Sprintf("%s.log", time.Now().Format("2006-01-02_15:04:05"))
folderPath := path.Join(os.ExpandEnv("$HOME"), ".simapp", "simulations")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this always simapp?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used only for simulations, so it lgtm

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah but more apps rely on this "module", including gaia, so it would check for the .simapp directory

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just use simulation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be fixed in master first.

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