Skip to content

Commit

Permalink
Use logrus directly instead of providing a wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfonso Acosta committed Feb 5, 2016
1 parent 12b633f commit 8b8a332
Show file tree
Hide file tree
Showing 22 changed files with 161 additions and 160 deletions.
6 changes: 3 additions & 3 deletions app/controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions app/pipes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand All @@ -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()},
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/server_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"encoding/json"
"net/http"

. "github.com/weaveworks/scope/common"
log "github.com/Sirupsen/logrus"
)

func respondWith(w http.ResponseWriter, code int, response interface{}) {
w.Header().Set("Content-Type", "application/json")
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)
}
}
39 changes: 0 additions & 39 deletions common/log/log.go

This file was deleted.

4 changes: 2 additions & 2 deletions common/sanitize/sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
16 changes: 10 additions & 6 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
Expand All @@ -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
;;
Expand Down
18 changes: 9 additions & 9 deletions probe/appclient/app_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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:
Expand All @@ -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()
}()

Expand All @@ -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)
}()
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
})
Expand Down
7 changes: 4 additions & 3 deletions probe/appclient/multi_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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}
Expand Down
5 changes: 3 additions & 2 deletions probe/appclient/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"strings"
"time"

. "github.com/weaveworks/scope/common/log"
log "github.com/Sirupsen/logrus"

"github.com/weaveworks/scope/common/xfer"
)

Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions probe/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()
Expand All @@ -198,21 +198,21 @@ 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
}()

var stats docker.Stats
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
Expand Down
4 changes: 2 additions & 2 deletions probe/docker/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 }()
Expand Down
Loading

0 comments on commit 8b8a332

Please sign in to comment.