diff --git a/common/cmd/cmd.go b/common/cmd/cmd.go index 93b7d7b1f..188783677 100644 --- a/common/cmd/cmd.go +++ b/common/cmd/cmd.go @@ -31,6 +31,8 @@ type Cmd struct { checkFuncs cmap.ConcurrentMap //map[string]checkFunc + // open log flag. + openLog bool // error channel ErrChan chan error } @@ -64,7 +66,7 @@ func (c *Cmd) runCmd() { // RunCmd parallel running when parallel is true. func (c *Cmd) RunCmd(parallel bool) { - fmt.Println("cmd: ", c.args) + fmt.Println("cmd:", c.args) if parallel { go c.runCmd() } else { @@ -72,12 +74,17 @@ func (c *Cmd) RunCmd(parallel bool) { } } +// OpenLog open cmd log by this api. +func (c *Cmd) OpenLog(open bool) { + c.openLog = open +} + func (c *Cmd) Write(data []byte) (int, error) { out := string(data) - if verbose { - fmt.Printf("%s: %v", c.name, out) + if verbose || c.openLog { + fmt.Printf("%s:\n\t%v", c.name, out) } else if strings.Contains(out, "error") || strings.Contains(out, "warning") { - fmt.Printf("%s: %v", c.name, out) + fmt.Printf("%s:\n\t%v", c.name, out) } go c.checkFuncs.IterCb(func(_ string, value interface{}) { check := value.(checkFunc) diff --git a/tests/integration-test/common.go b/tests/integration-test/common.go index 3663eaba6..71f069cf4 100644 --- a/tests/integration-test/common.go +++ b/tests/integration-test/common.go @@ -78,6 +78,7 @@ func free(t *testing.T) { } type appAPI interface { + OpenLog(open bool) WaitResult(t *testing.T, timeout time.Duration, keyword string) bool RunApp(waitResult func() bool) WaitExit() @@ -86,33 +87,44 @@ type appAPI interface { func runMsgRelayerApp(t *testing.T, args ...string) appAPI { args = append(args, "--log.debug", "--config", bridgeFile) - return cmd.NewCmd("message-relayer-test", args...) + app := cmd.NewCmd("message-relayer-test", args...) + app.OpenLog(true) + return app } func runGasOracleApp(t *testing.T, args ...string) appAPI { args = append(args, "--log.debug", "--config", bridgeFile) - return cmd.NewCmd("gas-oracle-test", args...) + app := cmd.NewCmd("gas-oracle-test", args...) + app.OpenLog(true) + return app } func runRollupRelayerApp(t *testing.T, args ...string) appAPI { args = append(args, "--log.debug", "--config", bridgeFile) - return cmd.NewCmd("rollup-relayer-test", args...) + app := cmd.NewCmd("rollup-relayer-test", args...) + app.OpenLog(true) + return app } func runEventWatcherApp(t *testing.T, args ...string) appAPI { args = append(args, "--log.debug", "--config", bridgeFile) - return cmd.NewCmd("event-watcher-test", args...) + app := cmd.NewCmd("event-watcher-test", args...) + app.OpenLog(true) + return app } func runCoordinatorApp(t *testing.T, args ...string) appAPI { args = append(args, "--log.debug", "--config", coordinatorFile, "--ws", "--ws.port", strconv.Itoa(int(wsPort))) // start process - return cmd.NewCmd("coordinator-test", args...) + app := cmd.NewCmd("coordinator-test", args...) + app.OpenLog(true) + return app } func runDBCliApp(t *testing.T, option, keyword string) { args := []string{option, "--config", dbFile} app := cmd.NewCmd("db_cli-test", args...) + app.OpenLog(true) defer app.WaitExit() // Wait expect result. @@ -122,7 +134,9 @@ func runDBCliApp(t *testing.T, option, keyword string) { func runRollerApp(t *testing.T, args ...string) appAPI { args = append(args, "--log.debug", "--config", rollerFile) - return cmd.NewCmd("roller-test", args...) + app := cmd.NewCmd("roller-test", args...) + app.OpenLog(true) + return app } func runSender(t *testing.T, endpoint string) *sender.Sender {