diff --git a/app/controls.go b/app/controls.go index aa85141aed..0f5c38f6b1 100644 --- a/app/controls.go +++ b/app/controls.go @@ -6,9 +6,9 @@ import ( "net/rpc" "sync" + log "github.com/Sirupsen/logrus" "github.com/gorilla/mux" - . "github.com/weaveworks/scope/common/log" "github.com/weaveworks/scope/common/xfer" ) @@ -73,7 +73,7 @@ func (cr *controlRouter) handleControl(w http.ResponseWriter, r *http.Request) { ) handler, ok := cr.get(probeID) if !ok { - Log.Errorf("Probe %s is not connected right now...", probeID) + log.Errorf("Probe %s is not connected right now...", probeID) http.NotFound(w, r) return } @@ -101,7 +101,7 @@ func (cr *controlRouter) handleProbeWS(w http.ResponseWriter, r *http.Request) { conn, err := upgrader.Upgrade(w, r, nil) if err != nil { - Log.Errorf("Error upgrading to websocket: %v", err) + log.Errorf("Error upgrading to websocket: %v", err) return } defer conn.Close() diff --git a/app/pipes.go b/app/pipes.go index 54626bd432..bed35309b7 100644 --- a/app/pipes.go +++ b/app/pipes.go @@ -6,9 +6,9 @@ import ( "sync" "time" + log "github.com/Sirupsen/logrus" "github.com/gorilla/mux" - . "github.com/weaveworks/scope/common/log" "github.com/weaveworks/scope/common/mtime" "github.com/weaveworks/scope/common/xfer" ) @@ -99,7 +99,7 @@ func (pr *PipeRouter) timeout() { if (pipe.ui.refCount == 0 && now.Sub(pipe.ui.lastUsedTime) >= pipeTimeout) || (pipe.probe.refCount == 0 && now.Sub(pipe.probe.lastUsedTime) >= pipeTimeout) { - Log.Infof("Timing out pipe %s", id) + log.Infof("Timing out pipe %s", id) pipe.Close() pipe.tombstoneTime = now } @@ -122,7 +122,7 @@ func (pr *PipeRouter) getOrCreate(id string) (*pipe, bool) { defer pr.Unlock() p, ok := pr.pipes[id] if !ok { - Log.Infof("Creating pipe id %s", id) + log.Infof("Creating pipe id %s", id) p = &pipe{ ui: end{lastUsedTime: mtime.Now()}, probe: end{lastUsedTime: mtime.Now()}, @@ -178,7 +178,7 @@ func (pr *PipeRouter) handleWs(endSelector func(*pipe) (*end, io.ReadWriter)) fu conn, err := upgrader.Upgrade(w, r, nil) if err != nil { - Log.Errorf("Error upgrading to websocket: %v", err) + log.Errorf("Error upgrading to websocket: %v", err) return } defer conn.Close() @@ -191,7 +191,7 @@ func (pr *PipeRouter) delete(w http.ResponseWriter, r *http.Request) { pipeID := mux.Vars(r)["pipeID"] pipe, ok := pr.getOrCreate(pipeID) if ok && pr.retain(pipeID, pipe, &pipe.ui) { - Log.Infof("Closing pipe %s", pipeID) + log.Infof("Closing pipe %s", pipeID) pipe.Close() pipe.tombstoneTime = mtime.Now() pr.release(pipeID, pipe, &pipe.ui) diff --git a/app/server_helpers.go b/app/server_helpers.go index b3b772f707..815ceb4a50 100644 --- a/app/server_helpers.go +++ b/app/server_helpers.go @@ -4,7 +4,7 @@ import ( "encoding/json" "net/http" - . "github.com/weaveworks/scope/common" + log "github.com/Sirupsen/logrus" ) func respondWith(w http.ResponseWriter, code int, response interface{}) { @@ -12,6 +12,6 @@ func respondWith(w http.ResponseWriter, code int, response interface{}) { w.Header().Add("Cache-Control", "no-cache") w.WriteHeader(code) if err := json.NewEncoder(w).Encode(response); err != nil { - Log.Error(err) + log.Error(err) } } diff --git a/common/log/log.go b/common/log/log.go deleted file mode 100644 index dea12b6fbb..0000000000 --- a/common/log/log.go +++ /dev/null @@ -1,39 +0,0 @@ -package log - -// Logger for Scope piggi-backing on github.com/weaveworks/weave/common.Log - -import ( - "github.com/Sirupsen/logrus" - - weavecommon "github.com/weaveworks/weave/common" -) - -var ( - prefix []byte - Log *logrus.Logger -) - -type prefixFormatter struct { - next logrus.Formatter -} - -func (f *prefixFormatter) Format(entry *logrus.Entry) ([]byte, error) { - log, err := f.next.Format(entry) - if err != nil { - return log, err - } - return append(prefix, log...), nil -} - -func init() { - Log = weavecommon.Log - Log.Formatter = &prefixFormatter{Log.Formatter} -} - -func SetLogLevel(levelname string) { - weavecommon.SetLogLevel(levelname) -} - -func SetLogPrefix(s string) { - prefix = []byte(s) -} diff --git a/common/sanitize/sanitize.go b/common/sanitize/sanitize.go index 59f9297fe0..0ba4eae074 100644 --- a/common/sanitize/sanitize.go +++ b/common/sanitize/sanitize.go @@ -6,7 +6,7 @@ import ( "net/url" "strings" - . "github.com/weaveworks/scope/common/log" + log "github.com/Sirupsen/logrus" ) // URL returns a function that sanitizes a URL string. It lets underspecified @@ -24,7 +24,7 @@ func URL(defaultScheme string, defaultPort int, defaultPath string) func(string) } u, err := url.Parse(s) if err != nil { - Log.Errorf("%q: %v", s, err) + log.Errorf("%q: %v", s, err) return s // oh well } if _, port, err := net.SplitHostPort(u.Host); err != nil && defaultPort > 0 { diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index a58e0f5bf8..d2d02908c9 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -88,6 +88,16 @@ while true; do fi APP_ARGS="$APP_ARGS -$ARG_NAME=$ARG_VALUE" ;; + --debug) + APP_ARGS="$APP_ARGS -log-level=debug" + PROBE_ARGS="$PROBE_ARGS -log-level=debug" + ;; + --no-app) + touch /etc/service/app/down + ;; + --no-probe) + touch /etc/service/probe/down + ;; --probe.*) if echo "$1" | grep "=" 1>/dev/null; then ARG_NAME=$(echo "$1" | sed 's/\-\-probe\.\([^=]*\)=\(.*\)/\1/') @@ -112,12 +122,6 @@ while true; do TOKEN_PROVIDED=true touch /etc/service/app/down ;; - --no-app) - touch /etc/service/app/down - ;; - --no-probe) - touch /etc/service/probe/down - ;; *) break ;; diff --git a/probe/appclient/app_client.go b/probe/appclient/app_client.go index 6f90345101..c20e3d80a4 100644 --- a/probe/appclient/app_client.go +++ b/probe/appclient/app_client.go @@ -9,9 +9,9 @@ import ( "sync" "time" + log "github.com/Sirupsen/logrus" "github.com/gorilla/websocket" - . "github.com/weaveworks/scope/common/log" "github.com/weaveworks/scope/common/sanitize" "github.com/weaveworks/scope/common/xfer" ) @@ -170,7 +170,7 @@ func (c *appClient) doWithBackoff(msg string, f func() (bool, error)) { continue } - Log.Errorf("Error doing %s for %s, backing off %s: %v", msg, c.target, backoff, err) + log.Errorf("Error doing %s for %s, backing off %s: %v", msg, c.target, backoff, err) select { case <-time.After(backoff): case <-c.quit: @@ -192,7 +192,7 @@ func (c *appClient) controlConnection() (bool, error) { return false, err } defer func() { - Log.Infof("Closing control connection to %s", c.target) + log.Infof("Closing control connection to %s", c.target) conn.Close() }() @@ -214,8 +214,8 @@ func (c *appClient) controlConnection() (bool, error) { func (c *appClient) ControlConnection() { go func() { - Log.Infof("Control connection to %s starting", c.target) - defer Log.Infof("Control connection to %s exiting", c.target) + log.Infof("Control connection to %s starting", c.target) + defer log.Infof("Control connection to %s exiting", c.target) c.doWithBackoff("controls", c.controlConnection) }() } @@ -242,8 +242,8 @@ func (c *appClient) publish(r io.Reader) error { func (c *appClient) startPublishing() { go func() { - Log.Infof("Publish loop for %s starting", c.target) - defer Log.Infof("Publish loop for %s exiting", c.target) + log.Infof("Publish loop for %s starting", c.target) + defer log.Infof("Publish loop for %s exiting", c.target) c.doWithBackoff("publish", func() (bool, error) { r := <-c.readers if r == nil { @@ -291,8 +291,8 @@ func (c *appClient) pipeConnection(id string, pipe xfer.Pipe) (bool, error) { func (c *appClient) PipeConnection(id string, pipe xfer.Pipe) { go func() { - Log.Infof("Pipe %s connection to %s starting", id, c.target) - defer Log.Infof("Pipe %s connection to %s exiting", id, c.target) + log.Infof("Pipe %s connection to %s starting", id, c.target) + defer log.Infof("Pipe %s connection to %s exiting", id, c.target) c.doWithBackoff(id, func() (bool, error) { return c.pipeConnection(id, pipe) }) diff --git a/probe/appclient/multi_client.go b/probe/appclient/multi_client.go index 3c0d7cce8c..3fc9fa6d6f 100644 --- a/probe/appclient/multi_client.go +++ b/probe/appclient/multi_client.go @@ -9,7 +9,8 @@ import ( "strings" "sync" - . "github.com/weaveworks/scope/common/log" + log "github.com/Sirupsen/logrus" + "github.com/weaveworks/scope/common/xfer" "github.com/weaveworks/scope/report" ) @@ -75,13 +76,13 @@ func (c *multiClient) Set(hostname string, endpoints []string) { client, err := c.clientFactory(hostname, endpoint) if err != nil { - Log.Errorf("Error creating new app client: %v", err) + log.Errorf("Error creating new app client: %v", err) return } details, err := client.Details() if err != nil { - Log.Errorf("Error fetching app details: %v", err) + log.Errorf("Error fetching app details: %v", err) } clients <- clientTuple{details, client} diff --git a/probe/appclient/resolver.go b/probe/appclient/resolver.go index 536a5aecc1..6990e1f189 100644 --- a/probe/appclient/resolver.go +++ b/probe/appclient/resolver.go @@ -6,7 +6,8 @@ import ( "strings" "time" - . "github.com/weaveworks/scope/common/log" + log "github.com/Sirupsen/logrus" + "github.com/weaveworks/scope/common/xfer" ) @@ -74,7 +75,7 @@ func prepare(strs []string) []target { var err error host, port, err = net.SplitHostPort(s) if err != nil { - Log.Errorf("invalid address %s: %v", s, err) + log.Errorf("invalid address %s: %v", s, err) continue } } else { diff --git a/probe/docker/container.go b/probe/docker/container.go index 68e0f11d1b..b5e89f8f8e 100644 --- a/probe/docker/container.go +++ b/probe/docker/container.go @@ -14,9 +14,9 @@ import ( "sync" "time" + log "github.com/Sirupsen/logrus" docker "github.com/fsouza/go-dockerclient" - . "github.com/weaveworks/scope/common/log" "github.com/weaveworks/scope/common/mtime" "github.com/weaveworks/scope/report" ) @@ -162,30 +162,30 @@ func (c *container) StartGatheringStats() error { } go func() { - Log.Infof("docker container: collecting stats for %s", c.container.ID) + log.Infof("docker container: collecting stats for %s", c.container.ID) req, err := http.NewRequest("GET", fmt.Sprintf("/containers/%s/stats", c.container.ID), nil) if err != nil { - Log.Errorf("docker container: %v", err) + log.Errorf("docker container: %v", err) return } req.Header.Set("User-Agent", "weavescope") url, err := url.Parse(endpoint) if err != nil { - Log.Errorf("docker container: %v", err) + log.Errorf("docker container: %v", err) return } dial, err := DialStub(url.Scheme, url.Path) if err != nil { - Log.Errorf("docker container: %v", err) + log.Errorf("docker container: %v", err) return } conn := NewClientConnStub(dial, nil) resp, err := conn.Do(req) if err != nil { - Log.Errorf("docker container: %v", err) + log.Errorf("docker container: %v", err) return } defer resp.Body.Close() @@ -198,7 +198,7 @@ func (c *container) StartGatheringStats() error { c.Lock() defer c.Unlock() - Log.Infof("docker container: stopped collecting stats for %s", c.container.ID) + log.Infof("docker container: stopped collecting stats for %s", c.container.ID) c.statsConn = nil }() @@ -206,13 +206,13 @@ func (c *container) StartGatheringStats() error { decoder := json.NewDecoder(resp.Body) for err := decoder.Decode(&stats); err != io.EOF; err = decoder.Decode(&stats) { if err != nil { - Log.Errorf("docker container: error reading event, did container stop? %v", err) + log.Errorf("docker container: error reading event, did container stop? %v", err) return } c.Lock() if c.numPending >= len(c.pendingStats) { - Log.Warnf("docker container: dropping stats.") + log.Warnf("docker container: dropping stats.") } else { c.latestStats = stats c.pendingStats[c.numPending] = stats diff --git a/probe/docker/container_test.go b/probe/docker/container_test.go index 90ae11e052..e2c52f64e4 100644 --- a/probe/docker/container_test.go +++ b/probe/docker/container_test.go @@ -10,9 +10,9 @@ import ( "testing" "time" + log "github.com/Sirupsen/logrus" client "github.com/fsouza/go-dockerclient" - . "github.com/weaveworks/scope/common/log" "github.com/weaveworks/scope/common/mtime" "github.com/weaveworks/scope/probe/docker" "github.com/weaveworks/scope/report" @@ -35,7 +35,7 @@ func (c *mockConnection) Close() error { } func TestContainer(t *testing.T) { - Log.SetOutput(ioutil.Discard) + log.SetOutput(ioutil.Discard) oldDialStub, oldNewClientConnStub := docker.DialStub, docker.NewClientConnStub defer func() { docker.DialStub, docker.NewClientConnStub = oldDialStub, oldNewClientConnStub }() diff --git a/probe/docker/controls.go b/probe/docker/controls.go index e9d0d587af..293bc36eed 100644 --- a/probe/docker/controls.go +++ b/probe/docker/controls.go @@ -3,7 +3,8 @@ package docker import ( docker_client "github.com/fsouza/go-dockerclient" - . "github.com/weaveworks/scope/common/log" + log "github.com/Sirupsen/logrus" + "github.com/weaveworks/scope/common/xfer" "github.com/weaveworks/scope/probe/controls" "github.com/weaveworks/scope/report" @@ -23,27 +24,27 @@ const ( ) func (r *registry) stopContainer(containerID string, _ xfer.Request) xfer.Response { - Log.Infof("Stopping container %s", containerID) + log.Infof("Stopping container %s", containerID) return xfer.ResponseError(r.client.StopContainer(containerID, waitTime)) } func (r *registry) startContainer(containerID string, _ xfer.Request) xfer.Response { - Log.Infof("Starting container %s", containerID) + log.Infof("Starting container %s", containerID) return xfer.ResponseError(r.client.StartContainer(containerID, nil)) } func (r *registry) restartContainer(containerID string, _ xfer.Request) xfer.Response { - Log.Infof("Restarting container %s", containerID) + log.Infof("Restarting container %s", containerID) return xfer.ResponseError(r.client.RestartContainer(containerID, waitTime)) } func (r *registry) pauseContainer(containerID string, _ xfer.Request) xfer.Response { - Log.Infof("Pausing container %s", containerID) + log.Infof("Pausing container %s", containerID) return xfer.ResponseError(r.client.PauseContainer(containerID)) } func (r *registry) unpauseContainer(containerID string, _ xfer.Request) xfer.Response { - Log.Infof("Unpausing container %s", containerID) + log.Infof("Unpausing container %s", containerID) return xfer.ResponseError(r.client.UnpauseContainer(containerID)) } @@ -75,14 +76,14 @@ func (r *registry) attachContainer(containerID string, req xfer.Request) xfer.Re } pipe.OnClose(func() { if err := cw.Close(); err != nil { - Log.Errorf("Error closing attachment: %v", err) + log.Errorf("Error closing attachment: %v", err) return } - Log.Infof("Attachment to container %s closed.", containerID) + log.Infof("Attachment to container %s closed.", containerID) }) go func() { if err := cw.Wait(); err != nil { - Log.Errorf("Error waiting on exec: %v", err) + log.Errorf("Error waiting on exec: %v", err) } pipe.Close() }() @@ -122,14 +123,14 @@ func (r *registry) execContainer(containerID string, req xfer.Request) xfer.Resp } pipe.OnClose(func() { if err := cw.Close(); err != nil { - Log.Errorf("Error closing exec: %v", err) + log.Errorf("Error closing exec: %v", err) return } - Log.Infof("Exec on container %s closed.", containerID) + log.Infof("Exec on container %s closed.", containerID) }) go func() { if err := cw.Wait(); err != nil { - Log.Errorf("Error waiting on exec: %v", err) + log.Errorf("Error waiting on exec: %v", err) } pipe.Close() }() diff --git a/probe/docker/registry.go b/probe/docker/registry.go index 0e964be2c1..c9e06c73bc 100644 --- a/probe/docker/registry.go +++ b/probe/docker/registry.go @@ -4,9 +4,9 @@ import ( "sync" "time" + log "github.com/Sirupsen/logrus" docker_client "github.com/fsouza/go-dockerclient" - . "github.com/weaveworks/scope/common/log" "github.com/weaveworks/scope/probe/controls" ) @@ -139,22 +139,22 @@ func (r *registry) listenForEvents() bool { // after listing but before listening for events. events := make(chan *docker_client.APIEvents) if err := r.client.AddEventListener(events); err != nil { - Log.Errorf("docker registry: %s", err) + log.Errorf("docker registry: %s", err) return true } defer func() { if err := r.client.RemoveEventListener(events); err != nil { - Log.Errorf("docker registry: %s", err) + log.Errorf("docker registry: %s", err) } }() if err := r.updateContainers(); err != nil { - Log.Errorf("docker registry: %s", err) + log.Errorf("docker registry: %s", err) return true } if err := r.updateImages(); err != nil { - Log.Errorf("docker registry: %s", err) + log.Errorf("docker registry: %s", err) return true } @@ -166,7 +166,7 @@ func (r *registry) listenForEvents() bool { case <-otherUpdates: if err := r.updateImages(); err != nil { - Log.Errorf("docker registry: %s", err) + log.Errorf("docker registry: %s", err) return true } @@ -241,7 +241,7 @@ func (r *registry) updateContainerState(containerID string) { if err != nil { // Don't spam the logs if the container was short lived if _, ok := err.(*docker_client.NoSuchContainer); !ok { - Log.Errorf("Error processing event for container %s: %v", containerID, err) + log.Errorf("Error processing event for container %s: %v", containerID, err) return } @@ -281,7 +281,7 @@ func (r *registry) updateContainerState(containerID string) { // And finally, ensure we gather stats for it if dockerContainer.State.Running { if err := c.StartGatheringStats(); err != nil { - Log.Errorf("Error gather stats for container: %s", containerID) + log.Errorf("Error gather stats for container: %s", containerID) return } } else { diff --git a/probe/docker/reporter.go b/probe/docker/reporter.go index c557ba76b5..6cab0728df 100644 --- a/probe/docker/reporter.go +++ b/probe/docker/reporter.go @@ -3,9 +3,9 @@ package docker import ( "net" + log "github.com/Sirupsen/logrus" docker_client "github.com/fsouza/go-dockerclient" - . "github.com/weaveworks/scope/common/log" "github.com/weaveworks/scope/probe" "github.com/weaveworks/scope/report" ) @@ -41,7 +41,7 @@ func (Reporter) Name() string { return "Docker" } func (r *Reporter) ContainerUpdated(c Container) { localAddrs, err := report.LocalAddresses() if err != nil { - Log.Errorf("Error getting local address: %v", err) + log.Errorf("Error getting local address: %v", err) return } diff --git a/probe/endpoint/conntrack.go b/probe/endpoint/conntrack.go index 43f5cfe27c..2b2f51051d 100644 --- a/probe/endpoint/conntrack.go +++ b/probe/endpoint/conntrack.go @@ -9,8 +9,9 @@ import ( "sync" "time" + log "github.com/Sirupsen/logrus" + "github.com/weaveworks/scope/common/exec" - . "github.com/weaveworks/scope/common/log" ) const ( @@ -86,7 +87,7 @@ type conntrackWalker struct { // newConntracker creates and starts a new conntracker. func newConntrackFlowWalker(useConntrack bool, args ...string) flowWalker { if !ConntrackModulePresent() { - Log.Info("Not using conntrack: module not present") + log.Info("Not using conntrack: module not present") return nilFlowWalker{} } else if !useConntrack { return nilFlowWalker{} @@ -117,10 +118,10 @@ var ConntrackModulePresent = func() bool { } } if err := scanner.Err(); err != nil { - Log.Errorf("conntrack error: %v", err) + log.Errorf("conntrack error: %v", err) } - Log.Errorf("conntrack: failed to find module %s", conntrackModule) + log.Errorf("conntrack: failed to find module %s", conntrackModule) return false } @@ -156,10 +157,10 @@ func (c *conntrackWalker) clearFlows() { func logPipe(prefix string, reader io.Reader) { scanner := bufio.NewScanner(reader) for scanner.Scan() { - Log.Error(prefix, scanner.Text()) + log.Error(prefix, scanner.Text()) } if err := scanner.Err(); err != nil { - Log.Error(prefix, err) + log.Error(prefix, err) } } @@ -168,7 +169,7 @@ func (c *conntrackWalker) run() { // for which we don't get events existingFlows, err := c.existingConnections() if err != nil { - Log.Errorf("conntrack existingConnections error: %v", err) + log.Errorf("conntrack existingConnections error: %v", err) return } for _, flow := range existingFlows { @@ -179,25 +180,25 @@ func (c *conntrackWalker) run() { cmd := exec.Command("conntrack", args...) stdout, err := cmd.StdoutPipe() if err != nil { - Log.Errorf("conntrack error: %v", err) + log.Errorf("conntrack error: %v", err) return } stderr, err := cmd.StderrPipe() if err != nil { - Log.Errorf("conntrack error: %v", err) + log.Errorf("conntrack error: %v", err) return } go logPipe("conntrack stderr:", stderr) if err := cmd.Start(); err != nil { - Log.Errorf("conntrack error: %v", err) + log.Errorf("conntrack error: %v", err) return } defer func() { if err := cmd.Wait(); err != nil { - Log.Errorf("conntrack error: %v", err) + log.Errorf("conntrack error: %v", err) } }() @@ -216,28 +217,28 @@ func (c *conntrackWalker) run() { // Swallow the first two lines reader := bufio.NewReader(stdout) if line, err := reader.ReadString('\n'); err != nil { - Log.Errorf("conntrack error: %v", err) + log.Errorf("conntrack error: %v", err) return } else if line != xmlHeader { - Log.Errorf("conntrack invalid output: '%s'", line) + log.Errorf("conntrack invalid output: '%s'", line) return } if line, err := reader.ReadString('\n'); err != nil { - Log.Errorf("conntrack error: %v", err) + log.Errorf("conntrack error: %v", err) return } else if line != conntrackOpenTag { - Log.Errorf("conntrack invalid output: '%s'", line) + log.Errorf("conntrack invalid output: '%s'", line) return } - defer Log.Infof("contrack exiting") + defer log.Infof("contrack exiting") // Now loop on the output stream decoder := xml.NewDecoder(reader) for { var f flow if err := decoder.Decode(&f); err != nil { - Log.Errorf("conntrack error: %v", err) + log.Errorf("conntrack error: %v", err) return } c.handleFlow(f, false) @@ -256,7 +257,7 @@ func (c *conntrackWalker) existingConnections() ([]flow, error) { } defer func() { if err := cmd.Wait(); err != nil { - Log.Errorf("conntrack existingConnections exit error: %v", err) + log.Errorf("conntrack existingConnections exit error: %v", err) } }() var result conntrack diff --git a/probe/endpoint/procspy/proc_linux.go b/probe/endpoint/procspy/proc_linux.go index 8ec86eea11..87ac4bd43e 100644 --- a/probe/endpoint/procspy/proc_linux.go +++ b/probe/endpoint/procspy/proc_linux.go @@ -8,11 +8,11 @@ import ( "strconv" "syscall" + log "github.com/Sirupsen/logrus" "github.com/armon/go-metrics" "github.com/hashicorp/go-version" "github.com/weaveworks/scope/common/fs" - . "github.com/weaveworks/scope/common/log" "github.com/weaveworks/scope/common/marshal" "github.com/weaveworks/scope/probe/process" ) @@ -54,7 +54,7 @@ func getNetNamespacePathSuffix() string { v, err := getKernelVersion() if err != nil { - Log.Errorf("getNeNameSpacePath: cannot get kernel version: %s\n", err) + log.Errorf("getNeNameSpacePath: cannot get kernel version: %s\n", err) netNamespacePathSuffix = post38Path return netNamespacePathSuffix } diff --git a/probe/kubernetes/client.go b/probe/kubernetes/client.go index 54a61eb073..4f527c3150 100644 --- a/probe/kubernetes/client.go +++ b/probe/kubernetes/client.go @@ -3,14 +3,13 @@ package kubernetes import ( "time" + log "github.com/Sirupsen/logrus" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/client/cache" "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/util" - - . "github.com/weaveworks/scope/common/log" ) // These constants are keys used in node metadata @@ -39,7 +38,7 @@ type client struct { func runReflectorUntil(r *cache.Reflector, resyncPeriod time.Duration, stopCh <-chan struct{}) { loggingListAndWatch := func() { if err := r.ListAndWatch(stopCh); err != nil { - Log.Errorf("Kubernetes reflector: %v", err) + log.Errorf("Kubernetes reflector: %v", err) } } go util.Until(loggingListAndWatch, resyncPeriod, stopCh) diff --git a/probe/overlay/weave.go b/probe/overlay/weave.go index a1391423e3..2357d4d5f8 100644 --- a/probe/overlay/weave.go +++ b/probe/overlay/weave.go @@ -11,7 +11,7 @@ import ( "time" "github.com/weaveworks/scope/common/exec" - . "github.com/weaveworks/scope/common/log" + log "github.com/Sirupsen/logrus" "github.com/weaveworks/scope/common/sanitize" "github.com/weaveworks/scope/probe/docker" "github.com/weaveworks/scope/report" @@ -99,7 +99,7 @@ func (w *Weave) loop() { for { psEntries, err := w.getPSEntries() if err != nil { - Log.Errorf("Error running weave ps: %v", err) + log.Errorf("Error running weave ps: %v", err) break } @@ -166,7 +166,7 @@ func (w *Weave) getPSEntries() ([]psEntry, error) { } defer func() { if err := cmd.Wait(); err != nil { - Log.Errorf("Weave tagger, cmd failed: %v", err) + log.Errorf("Weave tagger, cmd failed: %v", err) } }() scanner := bufio.NewScanner(out) diff --git a/probe/probe.go b/probe/probe.go index a62d09b776..716876004c 100644 --- a/probe/probe.go +++ b/probe/probe.go @@ -4,9 +4,9 @@ import ( "sync" "time" + log "github.com/Sirupsen/logrus" "github.com/armon/go-metrics" - . "github.com/weaveworks/scope/common/log" "github.com/weaveworks/scope/probe/appclient" "github.com/weaveworks/scope/report" ) @@ -123,7 +123,7 @@ func (p *Probe) tick() { err := ticker.Tick() metrics.MeasureSince([]string{ticker.Name(), "ticker"}, t) if err != nil { - Log.Errorf("error doing ticker: %v", err) + log.Errorf("error doing ticker: %v", err) } } } @@ -136,7 +136,7 @@ func (p *Probe) report() report.Report { newReport, err := rep.Report() metrics.MeasureSince([]string{rep.Name(), "reporter"}, t) if err != nil { - Log.Errorf("error generating report: %v", err) + log.Errorf("error generating report: %v", err) newReport = report.MakeReport() // empty is OK to merge } reports <- newReport @@ -157,7 +157,7 @@ func (p *Probe) tag(r report.Report) report.Report { r, err = tagger.Tag(r) metrics.MeasureSince([]string{tagger.Name(), "tagger"}, t) if err != nil { - Log.Errorf("error applying tagger: %v", err) + log.Errorf("error applying tagger: %v", err) } } return r @@ -175,7 +175,7 @@ ForLoop: } if err := p.publisher.Publish(rpt); err != nil { - Log.Infof("publish: %v", err) + log.Infof("publish: %v", err) } } diff --git a/prog/app.go b/prog/app.go index 7e17dd3d32..d0e781e9e7 100644 --- a/prog/app.go +++ b/prog/app.go @@ -9,12 +9,12 @@ import ( "strings" "time" + log "github.com/Sirupsen/logrus" "github.com/gorilla/mux" "github.com/weaveworks/go-checkpoint" "github.com/weaveworks/weave/common" "github.com/weaveworks/scope/app" - . "github.com/weaveworks/scope/common/log" "github.com/weaveworks/scope/common/xfer" ) @@ -37,14 +37,14 @@ func appMain() { ) flag.Parse() - SetLogLevel(*logLevel) + setLogLevel(*logLevel) if !strings.HasSuffix(*logPrefix, " ") { *logPrefix += " " } - SetLogPrefix(*logPrefix) + setLogFormatter(*logPrefix) - defer Log.Info("app exiting") + defer log.Info("app exiting") // Start background version checking checkpoint.CheckInterval(&checkpoint.CheckParams{ @@ -53,7 +53,7 @@ func appMain() { SignatureFile: signatureFile, }, versionCheckPeriod, func(r *checkpoint.CheckResponse, err error) { if r.Outdated { - Log.Infof("Scope version %s is available; please update at %s", + log.Infof("Scope version %s is available; please update at %s", r.CurrentVersion, r.CurrentDownloadURL) } }) @@ -61,11 +61,11 @@ func appMain() { rand.Seed(time.Now().UnixNano()) app.UniqueID = strconv.FormatInt(rand.Int63(), 16) app.Version = version - Log.Infof("app starting, version %s, ID %s", app.Version, app.UniqueID) + log.Infof("app starting, version %s, ID %s", app.Version, app.UniqueID) handler := router(app.NewCollector(*window)) go func() { - Log.Infof("listening on %s", *listen) - Log.Info(http.ListenAndServe(*listen, handler)) + log.Infof("listening on %s", *listen) + log.Info(http.ListenAndServe(*listen, handler)) }() common.SignalHandlerLoop() diff --git a/prog/main.go b/prog/main.go index cc66dd26ae..ab87b857f2 100644 --- a/prog/main.go +++ b/prog/main.go @@ -3,10 +3,43 @@ package main import ( "fmt" "os" + + log "github.com/Sirupsen/logrus" + weavecommon "github.com/weaveworks/weave/common" ) var version = "dev" // set at build time +type prefixFormatter struct { + prefix []byte + next log.Formatter +} + +func (f *prefixFormatter) Format(entry *log.Entry) ([]byte, error) { + formatted, err := f.next.Format(entry) + if err != nil { + return formatted, err + } + return append(f.prefix, formatted...), nil +} + +func setLogFormatter(prefix string) { + f := prefixFormatter{ + prefix: []byte(prefix), + // reuse weave's log format + next: weavecommon.Log.Formatter, + } + log.SetFormatter(&f) +} + +func setLogLevel(levelname string) { + level, err := log.ParseLevel(levelname) + if err != nil { + log.Fatal(err) + } + log.SetLevel(level) +} + func usage() { fmt.Fprintf(os.Stderr, "usage: %s (app|probe|version) args...\n", os.Args[0]) os.Exit(1) diff --git a/prog/probe.go b/prog/probe.go index a2e1061e1a..d3d8b5702a 100644 --- a/prog/probe.go +++ b/prog/probe.go @@ -12,12 +12,12 @@ import ( "strings" "time" + log "github.com/Sirupsen/logrus" "github.com/armon/go-metrics" "github.com/weaveworks/go-checkpoint" "github.com/weaveworks/weave/common" "github.com/weaveworks/scope/common/hostname" - . "github.com/weaveworks/scope/common/log" "github.com/weaveworks/scope/common/xfer" "github.com/weaveworks/scope/probe" "github.com/weaveworks/scope/probe/appclient" @@ -39,9 +39,9 @@ const ( func check() { handleResponse := func(r *checkpoint.CheckResponse, err error) { if err != nil { - Log.Errorf("Error checking version: %v", err) + log.Errorf("Error checking version: %v", err) } else if r.Outdated { - Log.Infof("Scope version %s is available; please update at %s", + log.Infof("Scope version %s is available; please update at %s", r.CurrentVersion, r.CurrentDownloadURL) } } @@ -81,12 +81,12 @@ func probeMain() { ) flag.Parse() - SetLogLevel(*logLevel) + setLogLevel(*logLevel) if !strings.HasSuffix(*logPrefix, " ") { *logPrefix += " " } - SetLogPrefix(*logPrefix) + setLogFormatter(*logPrefix) // Setup in memory metrics sink inm := metrics.NewInmemSink(time.Minute, 2*time.Minute) @@ -94,10 +94,10 @@ func probeMain() { defer sig.Stop() metrics.NewGlobal(metrics.DefaultConfig("scope-probe"), inm) - defer Log.Info("probe exiting") + defer log.Info("probe exiting") if *spyProcs && os.Getegid() != 0 { - Log.Warn("-process=true, but that requires root to find everything") + log.Warn("-process=true, but that requires root to find everything") } rand.Seed(time.Now().UnixNano()) @@ -106,12 +106,12 @@ func probeMain() { hostName = hostname.Get() hostID = hostName // TODO(pb): we should sanitize the hostname ) - Log.Infof("probe starting, version %s, ID %s", version, probeID) + log.Infof("probe starting, version %s, ID %s", version, probeID) go check() addrs, err := net.InterfaceAddrs() if err != nil { - Log.Fatal(err) + log.Fatal(err) } localNets := report.Networks{} for _, addr := range addrs { @@ -124,7 +124,7 @@ func probeMain() { if len(flag.Args()) > 0 { targets = flag.Args() } - Log.Infof("publishing to: %s", strings.Join(targets, ", ")) + log.Infof("publishing to: %s", strings.Join(targets, ", ")) probeConfig := appclient.ProbeConfig{ Token: *token, @@ -158,14 +158,14 @@ func probeMain() { if *dockerEnabled { if err := report.AddLocalBridge(*dockerBridge); err != nil { - Log.Errorf("Docker: problem with bridge %s: %v", *dockerBridge, err) + log.Errorf("Docker: problem with bridge %s: %v", *dockerBridge, err) } if registry, err := docker.NewRegistry(*dockerInterval, clients); err == nil { defer registry.Stop() p.AddTagger(docker.NewTagger(registry, processCache)) p.AddReporter(docker.NewReporter(registry, hostID, p)) } else { - Log.Errorf("Docker: failed to start registry: %v", err) + log.Errorf("Docker: failed to start registry: %v", err) } } @@ -174,8 +174,8 @@ func probeMain() { defer client.Stop() p.AddReporter(kubernetes.NewReporter(client)) } else { - Log.Errorf("Kubernetes: failed to start client: %v", err) - Log.Errorf("Kubernetes: make sure to run Scope inside a POD with a service account or provide a valid kubernetes.api url") + log.Errorf("Kubernetes: failed to start client: %v", err) + log.Errorf("Kubernetes: make sure to run Scope inside a POD with a service account or provide a valid kubernetes.api url") } } @@ -189,9 +189,9 @@ func probeMain() { if *httpListen != "" { go func() { - Log.Infof("Profiling data being exported to %s", *httpListen) - Log.Infof("go tool pprof http://%s/debug/pprof/{profile,heap,block}", *httpListen) - Log.Infof("Profiling endpoint %s terminated: %v", *httpListen, http.ListenAndServe(*httpListen, nil)) + log.Infof("Profiling data being exported to %s", *httpListen) + log.Infof("go tool pprof http://%s/debug/pprof/{profile,heap,block}", *httpListen) + log.Infof("Profiling endpoint %s terminated: %v", *httpListen, http.ListenAndServe(*httpListen, nil)) }() }