Specify log visibility with NewServer

This commit is contained in:
Derek Parker 2015-05-08 17:26:09 -05:00
parent 819c476aa9
commit 228587f6ba
3 changed files with 11 additions and 11 deletions

@ -3,9 +3,6 @@ package main
import (
"flag"
"fmt"
sys "golang.org/x/sys/unix"
"io/ioutil"
"log"
"net"
"os"
"os/exec"
@ -13,6 +10,8 @@ import (
"path/filepath"
"strconv"
sys "golang.org/x/sys/unix"
"github.com/derekparker/delve/service/rest"
"github.com/derekparker/delve/terminal"
)
@ -61,11 +60,6 @@ func main() {
os.Exit(0)
}
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
if !logEnabled {
log.SetOutput(ioutil.Discard)
}
// Collect launch arguments
var processArgs []string
var attachPid int
@ -121,7 +115,7 @@ func main() {
Listener: listener,
ProcessArgs: processArgs,
AttachPid: attachPid,
})
}, logEnabled)
go server.Run()
status := 0

@ -22,7 +22,7 @@ func withTestClient(name string, t *testing.T, fn func(c service.Client)) {
server := NewServer(&Config{
Listener: listener,
ProcessArgs: []string{protest.Fixtures[name].Path},
})
}, false)
go server.Run()
client := NewClient(listener.Addr().String())
defer client.Detach(true)

@ -1,6 +1,7 @@
package rest
import (
"io/ioutil"
"log"
"net"
"net/http"
@ -41,7 +42,12 @@ type Config struct {
}
// NewServer creates a new RESTServer.
func NewServer(config *Config) *RESTServer {
func NewServer(config *Config, logEnabled bool) *RESTServer {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
if !logEnabled {
log.SetOutput(ioutil.Discard)
}
return &RESTServer{
config: config,
listener: config.Listener,