From 11fe67f66f997527bb41347c2773be126bfd8df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 26 Jul 2019 02:40:06 +0200 Subject: [PATCH] pond: push logs to separate logfiles --- lotuspond/main.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lotuspond/main.go b/lotuspond/main.go index afb3860ba..2c48afccb 100644 --- a/lotuspond/main.go +++ b/lotuspond/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "io" "io/ioutil" "net/http" "os" @@ -21,6 +22,8 @@ const listenAddr = "127.0.0.1:2222" type runningNode struct { cmd *exec.Cmd meta nodeInfo + + stop func() } type api struct { @@ -60,9 +63,18 @@ func (api *api) Spawn() (nodeInfo, error) { } + errlogfile, err := os.OpenFile(dir + ".err.log", os.O_CREATE | os.O_WRONLY, 0644) + if err != nil { + return nodeInfo{}, err + } + logfile, err := os.OpenFile(dir + ".out.log", os.O_CREATE | os.O_WRONLY, 0644) + if err != nil { + return nodeInfo{}, err + } + cmd := exec.Command("./lotus", "daemon", genParam, "--api", fmt.Sprintf("%d", 2500+id)) - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout + cmd.Stderr = io.MultiWriter(os.Stderr, errlogfile) + cmd.Stdout = io.MultiWriter(os.Stdout, logfile) cmd.Env = []string{"LOTUS_PATH=" + dir} if err := cmd.Start(); err != nil { return nodeInfo{}, err @@ -78,6 +90,11 @@ func (api *api) Spawn() (nodeInfo, error) { api.running[id] = runningNode{ cmd: cmd, meta: info, + + stop: func() { + defer errlogfile.Close() + defer logfile.Close() + }, } api.runningLk.Unlock()