Browse Source

tools/etcd-agent: write etcd log into log file

Yicheng Qin 10 years ago
parent
commit
061baad611
1 changed files with 14 additions and 3 deletions
  1. 14 3
      tools/functional-tester/etcd-agent/agent.go

+ 14 - 3
tools/functional-tester/etcd-agent/agent.go

@@ -22,8 +22,9 @@ import (
 )
 
 type Agent struct {
-	cmd *exec.Cmd
-	l   net.Listener
+	cmd     *exec.Cmd
+	logfile *os.File
+	l       net.Listener
 }
 
 func newAgent(etcd string) (*Agent, error) {
@@ -34,12 +35,20 @@ func newAgent(etcd string) (*Agent, error) {
 	}
 
 	c := exec.Command(etcd)
-	return &Agent{cmd: c}, nil
+
+	f, err := os.Create("etcd.log")
+	if err != nil {
+		return nil, err
+	}
+
+	return &Agent{cmd: c, logfile: f}, nil
 }
 
 // start starts a new etcd process with the given args.
 func (a *Agent) start(args ...string) error {
 	a.cmd = exec.Command(a.cmd.Path, args...)
+	a.cmd.Stdout = a.logfile
+	a.cmd.Stderr = a.logfile
 	return a.cmd.Start()
 }
 
@@ -56,6 +65,8 @@ func (a *Agent) stop() error {
 // restart restarts the stopped etcd process.
 func (a *Agent) restart() error {
 	a.cmd = exec.Command(a.cmd.Path, a.cmd.Args[1:]...)
+	a.cmd.Stdout = a.logfile
+	a.cmd.Stderr = a.logfile
 	return a.cmd.Start()
 }