add logrus

This commit is contained in:
Victor Vieux 2014-11-12 01:37:01 +00:00
parent 741f7adb56
commit 8f5f76ae41
3 changed files with 13 additions and 7 deletions

View File

@ -5,13 +5,13 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"regexp"
"sort"
"strings"
log "github.com/Sirupsen/logrus"
"github.com/docker/libcluster"
"github.com/gorilla/mux"
"github.com/samalba/dockerclient"
@ -165,12 +165,13 @@ func createRouter(c *libcluster.Cluster) (*mux.Router, error) {
for method, routes := range m {
for route, fct := range routes {
log.Printf("Registering %s, %s", method, route)
log.Debugf("Registering %s, %s", method, route)
// NOTE: scope issue, make sure the variables are local and won't be changed
localRoute := route
localFct := fct
wrap := func(w http.ResponseWriter, r *http.Request) {
fmt.Printf("-> %s %s\n", r.Method, r.RequestURI)
log.Infof("%s %s", r.Method, r.RequestURI)
localFct(c, w, r)
}
localMethod := method

View File

@ -3,12 +3,12 @@ package libcluster
import (
"crypto/tls"
"fmt"
"log"
"net"
"strings"
"sync"
"time"
log "github.com/Sirupsen/logrus"
"github.com/samalba/dockerclient"
)
@ -124,7 +124,7 @@ func (n *Node) updateState() error {
n.containers[container.Id] = container
}
log.Printf("[%s] Updated state", n.ID)
log.Debugf("[%s] Updated state", n.ID)
return nil
}
@ -142,7 +142,7 @@ func (n *Node) updateLoop() {
err = n.updateState()
}
if err != nil {
log.Printf("[%s] Updated state failed: %v", n.ID, err)
log.Errorf("[%s] Updated state failed: %v", n.ID, err)
}
}
}

View File

@ -2,9 +2,9 @@ package main
import (
"fmt"
"log"
"os"
log "github.com/Sirupsen/logrus"
"github.com/docker/libcluster"
"github.com/docker/libcluster/api"
)
@ -14,6 +14,11 @@ func main() {
fmt.Printf("Usage: %s node1 node2 ...\n", os.Args[0])
os.Exit(1)
}
// Setup logging
log.SetOutput(os.Stderr)
log.SetLevel(log.DebugLevel)
c := libcluster.NewCluster()
for _, addr := range os.Args[1:] {
n := libcluster.NewNode(addr, addr)