From 094106adfaf000a18c820fee8fba6179446f0d53 Mon Sep 17 00:00:00 2001 From: Helin Wang Date: Thu, 15 Jun 2017 22:25:54 +0000 Subject: [PATCH] use logrus for logging --- go/connection/conn.go | 5 +++-- go/master/c/client.go | 4 ++-- go/master/client.go | 14 +++++++------- go/pserver/cclient/cclient.go | 24 ++++++++++++------------ go/pserver/client.go | 6 +++--- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/go/connection/conn.go b/go/connection/conn.go index bc9b5f0617e..977e8cc1237 100644 --- a/go/connection/conn.go +++ b/go/connection/conn.go @@ -2,9 +2,10 @@ package connection import ( "errors" - "log" "net/rpc" "sync" + + log "github.com/sirupsen/logrus" ) // TODO(helin): add TCP re-connect logic @@ -65,7 +66,7 @@ func (c *Conn) Connect(addr string) error { } else { err := client.Close() if err != nil { - log.Println(err) + log.Errorln(err) } return errors.New("client already set from a concurrent goroutine") diff --git a/go/master/c/client.go b/go/master/c/client.go index 8a437eb2238..ed3e220d5ff 100644 --- a/go/master/c/client.go +++ b/go/master/c/client.go @@ -13,11 +13,11 @@ typedef int paddle_master_client; import "C" import ( - "log" "sync" "unsafe" "github.com/PaddlePaddle/Paddle/go/master" + log "github.com/sirupsen/logrus" ) var nullPtr = unsafe.Pointer(uintptr(0)) @@ -77,7 +77,7 @@ func paddle_set_dataset(client C.paddle_master_client, path **C.char, size C.int } err := c.SetDataset(paths) if err != nil { - log.Println(err) + log.Errorln(err) return C.PADDLE_MASTER_ERROR } diff --git a/go/master/client.go b/go/master/client.go index db6b17d2f0d..cd1408db3df 100644 --- a/go/master/client.go +++ b/go/master/client.go @@ -1,12 +1,12 @@ package master import ( - "log" "os" "time" "github.com/PaddlePaddle/Paddle/go/connection" "github.com/PaddlePaddle/recordio" + log "github.com/sirupsen/logrus" ) // Addresser provide the address of the master server. @@ -36,14 +36,14 @@ func (c *Client) getRecords() { if err != nil { // TODO(helin): wait before move on with next // getTask call. - log.Println(err) + log.Errorln(err) continue } for _, chunk := range t.Chunks { f, err := os.Open(chunk.Path) if err != nil { - log.Println(err) + log.Errorln(err) continue } @@ -53,12 +53,12 @@ func (c *Client) getRecords() { } if s.Err() != nil { - log.Println(err, chunk.Path) + log.Errorln(err, chunk.Path) } err = f.Close() if err != nil { - log.Println(err) + log.Errorln(err) } } @@ -79,12 +79,12 @@ func (c *Client) monitorMaster(addr Addresser) { if curMaster == "" { err := c.conn.Close() if err != nil { - log.Println(err) + log.Errorln(err) } } else { err := c.conn.Connect(curMaster) if err != nil { - log.Println(err) + log.Errorln(err) // connect to addr failed, set // to last known addr in order diff --git a/go/pserver/cclient/cclient.go b/go/pserver/cclient/cclient.go index 3e074a9f2aa..92a41b7f543 100644 --- a/go/pserver/cclient/cclient.go +++ b/go/pserver/cclient/cclient.go @@ -25,12 +25,12 @@ typedef int paddle_pserver_client; import "C" import ( - "log" "strings" "sync" "unsafe" "github.com/PaddlePaddle/Paddle/go/pserver" + log "github.com/sirupsen/logrus" ) var nullPtr = unsafe.Pointer(uintptr(0)) @@ -133,10 +133,10 @@ func paddle_init_param(client C.paddle_pserver_client, param C.paddle_parameter, if err != nil { if err.Error() == pserver.AlreadyInitialized { - log.Printf("parameter %s already initialized, treat paddle_init_param as sucessful.\n", name) + log.Warningf("parameter %s already initialized, treat paddle_init_param as sucessful.\n", name) return C.PSERVER_OK } - log.Println(err) + log.Errorln(err) return C.PSERVER_ERROR } @@ -149,11 +149,11 @@ func paddle_finish_init_params(client C.paddle_pserver_client) C.int { err := c.FinishInitParams() if err != nil { if err.Error() == pserver.AlreadyInitialized { - log.Println("parameters already initialized, treat paddle_finish_init_params as sucessful.") + log.Warningln("parameters already initialized, treat paddle_finish_init_params as sucessful.") return C.PSERVER_OK } - log.Println(err) + log.Errorln(err) return C.PSERVER_ERROR } @@ -174,7 +174,7 @@ func paddle_send_grads(client C.paddle_pserver_client, grads **C.paddle_gradient c := get(client) err := c.SendGrads(gs) if err != nil { - log.Println(err) + log.Errorln(err) return C.PSERVER_ERROR } @@ -191,7 +191,7 @@ func paddle_get_params(client C.paddle_pserver_client, dst **C.paddle_parameter, c := get(client) ps, err := c.GetParams(ns) if err != nil { - log.Println(err) + log.Errorln(err) return C.PSERVER_ERROR } @@ -200,7 +200,7 @@ func paddle_get_params(client C.paddle_pserver_client, dst **C.paddle_parameter, for i, p := range ps { pn[i] = p.Name } - log.Printf("pserver returned wrong number of parameters. Requested: %s, returned: %s.\n", strings.Join(pn, ", "), strings.Join(ns, ", ")) + log.Errorf("pserver returned wrong number of parameters. Requested: %s, returned: %s.\n", strings.Join(pn, ", "), strings.Join(ns, ", ")) return C.PSERVER_ERROR } @@ -210,7 +210,7 @@ func paddle_get_params(client C.paddle_pserver_client, dst **C.paddle_parameter, for i, p := range ps { pn[i] = p.Name } - log.Printf("pserver returned wrong parameters, or not in requested order. Requested: %s, returned: %s.\n", strings.Join(pn, ", "), strings.Join(ns, ", ")) + log.Errorf("pserver returned wrong parameters, or not in requested order. Requested: %s, returned: %s.\n", strings.Join(pn, ", "), strings.Join(ns, ", ")) return C.PSERVER_ERROR } } @@ -220,13 +220,13 @@ func paddle_get_params(client C.paddle_pserver_client, dst **C.paddle_parameter, param := *(**C.paddle_parameter)(unsafe.Pointer((uintptr(unsafe.Pointer(dst)) + uintptr(i)*unsafe.Sizeof(*dst)))) if unsafe.Pointer(param) == nullPtr { - log.Println("must pre-allocate parameter.") + log.Errorln("must pre-allocate parameter.") return C.PSERVER_ERROR } if unsafe.Pointer(param.content) != nullPtr { if int(param.content_len) != len(p.Content) { - log.Printf("the pre-allocated content len does not match parameter content len. Pre-allocated len: %d, returned len: %d", param.content_len, len(p.Content)) + log.Errorf("the pre-allocated content len does not match parameter content len. Pre-allocated len: %d, returned len: %d", param.content_len, len(p.Content)) return C.PSERVER_ERROR } } @@ -245,7 +245,7 @@ func paddle_save_model(client C.paddle_pserver_client, path *C.char) C.int { c := get(client) err := c.Save(p) if err != nil { - log.Println(err) + log.Errorln(err) return C.PSERVER_ERROR } diff --git a/go/pserver/client.go b/go/pserver/client.go index afe1eecd015..dda91597728 100644 --- a/go/pserver/client.go +++ b/go/pserver/client.go @@ -2,11 +2,11 @@ package pserver import ( "hash/fnv" - "log" "sort" "time" "github.com/PaddlePaddle/Paddle/go/connection" + log "github.com/sirupsen/logrus" ) // TODO(helin): add RPC call retry logic @@ -64,7 +64,7 @@ func (c *Client) monitorPservers(l Lister, pserverNum int) { if curServers[i].Addr == "" { err := c.pservers[i].Close() if err != nil { - log.Println(err) + log.Errorln(err) } continue @@ -72,7 +72,7 @@ func (c *Client) monitorPservers(l Lister, pserverNum int) { err := c.pservers[i].Connect(curServers[i].Addr) if err != nil { - log.Println(err) + log.Errorln(err) // connect to addr failed, set // to last known addr in order -- GitLab