提交 094106ad 编写于 作者: H Helin Wang

use logrus for logging

上级 e730bc59
...@@ -2,9 +2,10 @@ package connection ...@@ -2,9 +2,10 @@ package connection
import ( import (
"errors" "errors"
"log"
"net/rpc" "net/rpc"
"sync" "sync"
log "github.com/sirupsen/logrus"
) )
// TODO(helin): add TCP re-connect logic // TODO(helin): add TCP re-connect logic
...@@ -65,7 +66,7 @@ func (c *Conn) Connect(addr string) error { ...@@ -65,7 +66,7 @@ func (c *Conn) Connect(addr string) error {
} else { } else {
err := client.Close() err := client.Close()
if err != nil { if err != nil {
log.Println(err) log.Errorln(err)
} }
return errors.New("client already set from a concurrent goroutine") return errors.New("client already set from a concurrent goroutine")
......
...@@ -13,11 +13,11 @@ typedef int paddle_master_client; ...@@ -13,11 +13,11 @@ typedef int paddle_master_client;
import "C" import "C"
import ( import (
"log"
"sync" "sync"
"unsafe" "unsafe"
"github.com/PaddlePaddle/Paddle/go/master" "github.com/PaddlePaddle/Paddle/go/master"
log "github.com/sirupsen/logrus"
) )
var nullPtr = unsafe.Pointer(uintptr(0)) 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 ...@@ -77,7 +77,7 @@ func paddle_set_dataset(client C.paddle_master_client, path **C.char, size C.int
} }
err := c.SetDataset(paths) err := c.SetDataset(paths)
if err != nil { if err != nil {
log.Println(err) log.Errorln(err)
return C.PADDLE_MASTER_ERROR return C.PADDLE_MASTER_ERROR
} }
......
package master package master
import ( import (
"log"
"os" "os"
"time" "time"
"github.com/PaddlePaddle/Paddle/go/connection" "github.com/PaddlePaddle/Paddle/go/connection"
"github.com/PaddlePaddle/recordio" "github.com/PaddlePaddle/recordio"
log "github.com/sirupsen/logrus"
) )
// Addresser provide the address of the master server. // Addresser provide the address of the master server.
...@@ -36,14 +36,14 @@ func (c *Client) getRecords() { ...@@ -36,14 +36,14 @@ func (c *Client) getRecords() {
if err != nil { if err != nil {
// TODO(helin): wait before move on with next // TODO(helin): wait before move on with next
// getTask call. // getTask call.
log.Println(err) log.Errorln(err)
continue continue
} }
for _, chunk := range t.Chunks { for _, chunk := range t.Chunks {
f, err := os.Open(chunk.Path) f, err := os.Open(chunk.Path)
if err != nil { if err != nil {
log.Println(err) log.Errorln(err)
continue continue
} }
...@@ -53,12 +53,12 @@ func (c *Client) getRecords() { ...@@ -53,12 +53,12 @@ func (c *Client) getRecords() {
} }
if s.Err() != nil { if s.Err() != nil {
log.Println(err, chunk.Path) log.Errorln(err, chunk.Path)
} }
err = f.Close() err = f.Close()
if err != nil { if err != nil {
log.Println(err) log.Errorln(err)
} }
} }
...@@ -79,12 +79,12 @@ func (c *Client) monitorMaster(addr Addresser) { ...@@ -79,12 +79,12 @@ func (c *Client) monitorMaster(addr Addresser) {
if curMaster == "" { if curMaster == "" {
err := c.conn.Close() err := c.conn.Close()
if err != nil { if err != nil {
log.Println(err) log.Errorln(err)
} }
} else { } else {
err := c.conn.Connect(curMaster) err := c.conn.Connect(curMaster)
if err != nil { if err != nil {
log.Println(err) log.Errorln(err)
// connect to addr failed, set // connect to addr failed, set
// to last known addr in order // to last known addr in order
......
...@@ -25,12 +25,12 @@ typedef int paddle_pserver_client; ...@@ -25,12 +25,12 @@ typedef int paddle_pserver_client;
import "C" import "C"
import ( import (
"log"
"strings" "strings"
"sync" "sync"
"unsafe" "unsafe"
"github.com/PaddlePaddle/Paddle/go/pserver" "github.com/PaddlePaddle/Paddle/go/pserver"
log "github.com/sirupsen/logrus"
) )
var nullPtr = unsafe.Pointer(uintptr(0)) var nullPtr = unsafe.Pointer(uintptr(0))
...@@ -133,10 +133,10 @@ func paddle_init_param(client C.paddle_pserver_client, param C.paddle_parameter, ...@@ -133,10 +133,10 @@ func paddle_init_param(client C.paddle_pserver_client, param C.paddle_parameter,
if err != nil { if err != nil {
if err.Error() == pserver.AlreadyInitialized { 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 return C.PSERVER_OK
} }
log.Println(err) log.Errorln(err)
return C.PSERVER_ERROR return C.PSERVER_ERROR
} }
...@@ -149,11 +149,11 @@ func paddle_finish_init_params(client C.paddle_pserver_client) C.int { ...@@ -149,11 +149,11 @@ func paddle_finish_init_params(client C.paddle_pserver_client) C.int {
err := c.FinishInitParams() err := c.FinishInitParams()
if err != nil { if err != nil {
if err.Error() == pserver.AlreadyInitialized { 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 return C.PSERVER_OK
} }
log.Println(err) log.Errorln(err)
return C.PSERVER_ERROR return C.PSERVER_ERROR
} }
...@@ -174,7 +174,7 @@ func paddle_send_grads(client C.paddle_pserver_client, grads **C.paddle_gradient ...@@ -174,7 +174,7 @@ func paddle_send_grads(client C.paddle_pserver_client, grads **C.paddle_gradient
c := get(client) c := get(client)
err := c.SendGrads(gs) err := c.SendGrads(gs)
if err != nil { if err != nil {
log.Println(err) log.Errorln(err)
return C.PSERVER_ERROR return C.PSERVER_ERROR
} }
...@@ -191,7 +191,7 @@ func paddle_get_params(client C.paddle_pserver_client, dst **C.paddle_parameter, ...@@ -191,7 +191,7 @@ func paddle_get_params(client C.paddle_pserver_client, dst **C.paddle_parameter,
c := get(client) c := get(client)
ps, err := c.GetParams(ns) ps, err := c.GetParams(ns)
if err != nil { if err != nil {
log.Println(err) log.Errorln(err)
return C.PSERVER_ERROR return C.PSERVER_ERROR
} }
...@@ -200,7 +200,7 @@ func paddle_get_params(client C.paddle_pserver_client, dst **C.paddle_parameter, ...@@ -200,7 +200,7 @@ func paddle_get_params(client C.paddle_pserver_client, dst **C.paddle_parameter,
for i, p := range ps { for i, p := range ps {
pn[i] = p.Name 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 return C.PSERVER_ERROR
} }
...@@ -210,7 +210,7 @@ func paddle_get_params(client C.paddle_pserver_client, dst **C.paddle_parameter, ...@@ -210,7 +210,7 @@ func paddle_get_params(client C.paddle_pserver_client, dst **C.paddle_parameter,
for i, p := range ps { for i, p := range ps {
pn[i] = p.Name 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 return C.PSERVER_ERROR
} }
} }
...@@ -220,13 +220,13 @@ func paddle_get_params(client C.paddle_pserver_client, dst **C.paddle_parameter, ...@@ -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)))) param := *(**C.paddle_parameter)(unsafe.Pointer((uintptr(unsafe.Pointer(dst)) + uintptr(i)*unsafe.Sizeof(*dst))))
if unsafe.Pointer(param) == nullPtr { if unsafe.Pointer(param) == nullPtr {
log.Println("must pre-allocate parameter.") log.Errorln("must pre-allocate parameter.")
return C.PSERVER_ERROR return C.PSERVER_ERROR
} }
if unsafe.Pointer(param.content) != nullPtr { if unsafe.Pointer(param.content) != nullPtr {
if int(param.content_len) != len(p.Content) { 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 return C.PSERVER_ERROR
} }
} }
...@@ -245,7 +245,7 @@ func paddle_save_model(client C.paddle_pserver_client, path *C.char) C.int { ...@@ -245,7 +245,7 @@ func paddle_save_model(client C.paddle_pserver_client, path *C.char) C.int {
c := get(client) c := get(client)
err := c.Save(p) err := c.Save(p)
if err != nil { if err != nil {
log.Println(err) log.Errorln(err)
return C.PSERVER_ERROR return C.PSERVER_ERROR
} }
......
...@@ -2,11 +2,11 @@ package pserver ...@@ -2,11 +2,11 @@ package pserver
import ( import (
"hash/fnv" "hash/fnv"
"log"
"sort" "sort"
"time" "time"
"github.com/PaddlePaddle/Paddle/go/connection" "github.com/PaddlePaddle/Paddle/go/connection"
log "github.com/sirupsen/logrus"
) )
// TODO(helin): add RPC call retry logic // TODO(helin): add RPC call retry logic
...@@ -64,7 +64,7 @@ func (c *Client) monitorPservers(l Lister, pserverNum int) { ...@@ -64,7 +64,7 @@ func (c *Client) monitorPservers(l Lister, pserverNum int) {
if curServers[i].Addr == "" { if curServers[i].Addr == "" {
err := c.pservers[i].Close() err := c.pservers[i].Close()
if err != nil { if err != nil {
log.Println(err) log.Errorln(err)
} }
continue continue
...@@ -72,7 +72,7 @@ func (c *Client) monitorPservers(l Lister, pserverNum int) { ...@@ -72,7 +72,7 @@ func (c *Client) monitorPservers(l Lister, pserverNum int) {
err := c.pservers[i].Connect(curServers[i].Addr) err := c.pservers[i].Connect(curServers[i].Addr)
if err != nil { if err != nil {
log.Println(err) log.Errorln(err)
// connect to addr failed, set // connect to addr failed, set
// to last known addr in order // to last known addr in order
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册