logging method modify

This commit is contained in:
geek 2018-03-21 20:26:36 +09:00
parent 96d9105d30
commit 945c47c19a
6 changed files with 23 additions and 23 deletions

View File

@ -67,7 +67,7 @@ func (c *client) Connect() error {
c.ctx = c.ch.ClientContext(nil) c.ctx = c.ch.ClientContext(nil)
if err := c.ch.Init(c.ctx); nil != err { if err := c.ch.Init(c.ctx); nil != err {
logging.Logger().Panic(fmt.Sprintf("RPC Client: Initialization of client has been failed %v", err)) logging.Logger().Panicf("RPC Client: Initialization of client has been failed %v", err)
} }
if c.conn, err = c.rwcHandler.Connect(c.ctx); nil != err { if c.conn, err = c.rwcHandler.Connect(c.ctx); nil != err {
@ -84,7 +84,7 @@ func (c *client) Connect() error {
func (c *client) Close() { func (c *client) Close() {
if c.stopChan == nil { if c.stopChan == nil {
logging.Logger().Warn("RPC Client: the client must be started before stopping it") logging.Logger().Warnf("RPC Client: the client must be started before stopping it")
return return
} }
@ -94,7 +94,7 @@ func (c *client) Close() {
c.stopWg.Wait() c.stopWg.Wait()
c.stopChan = nil c.stopChan = nil
logging.Logger().Info(fmt.Sprintf("RPC Client: stopped")) logging.Logger().Infof("RPC Client: stopped")
} }
func (c *client) Send(method string, args ...interface{}) (err error) { func (c *client) Send(method string, args ...interface{}) (err error) {
@ -310,7 +310,7 @@ func (c *client) rpcWriter(stopChan <-chan struct{}, writerDone chan<- error) {
} }
if nil != err { if nil != err {
if err == io.ErrUnexpectedEOF || err == io.EOF { if err == io.ErrUnexpectedEOF || err == io.EOF {
logging.Logger().Info("Client: disconnected from server") logging.Logger().Infof("Client: disconnected from server")
return return
} }
@ -340,7 +340,7 @@ func (c *client) rpcReader(readerDone chan<- error) {
resCodec, err := c.rwcHandler.ReadResponse(c.ctx, c.ch.GetCodec(), c.conn) resCodec, err := c.rwcHandler.ReadResponse(c.ctx, c.ch.GetCodec(), c.conn)
if nil != err { if nil != err {
if err == io.ErrUnexpectedEOF || err == io.EOF { if err == io.ErrUnexpectedEOF || err == io.EOF {
logging.Logger().Info("Client: disconnected from server") logging.Logger().Infof("Client: disconnected from server")
return return
} }
err = fmt.Errorf("Client: Cannot decode response or notify: [%s]", err) err = fmt.Errorf("Client: Cannot decode response or notify: [%s]", err)

View File

@ -71,7 +71,7 @@ func (ch *ClientHandlers) GetRequestID() uint64 {
func (ch *ClientHandlers) Validate() { func (ch *ClientHandlers) Validate() {
if nil == ch.Codec { if nil == ch.Codec {
logging.Logger().Panic("RPC Client Handler: Codec must be specified") logging.Logger().Panicf("RPC Client Handler: Codec must be specified")
} }
if ch.RequestTimeout <= 0 { if ch.RequestTimeout <= 0 {

View File

@ -50,6 +50,6 @@ func (crwch *ClientReadWriteCloseHandlers) Validate() {
crwch.ClientReadWriteCloseHandlers.Validate() crwch.ClientReadWriteCloseHandlers.Validate()
if nil == crwch.SocketBuilder { if nil == crwch.SocketBuilder {
logging.Logger().Panic("RPC Client: SocketBuilder must be specified") logging.Logger().Panicf("RPC Client: SocketBuilder must be specified")
} }
} }

View File

@ -61,7 +61,7 @@ func (crwch *ClientReadWriteCloseHandlers) Validate() {
crwch.ClientReadWriteCloseHandlers.Validate() crwch.ClientReadWriteCloseHandlers.Validate()
if nil == crwch.SocketBuilder { if nil == crwch.SocketBuilder {
logging.Logger().Panic("RPC Client: SocketBuilder must be specified") logging.Logger().Panicf("RPC Client: SocketBuilder must be specified")
} }
} }

View File

@ -23,9 +23,9 @@ func (sh *ServletHandlers) Invoke(servletCTX rpc.ServletContext, requestCodec pr
result, err = sh.RPCInvoker.Invoke(requestCodec) result, err = sh.RPCInvoker.Invoke(requestCodec)
if nil != err { if nil != err {
if params, pErr := requestCodec.Params(); nil != err { if params, pErr := requestCodec.Params(); nil != err {
logging.Logger().Error(fmt.Sprintf("RPC Servlet Handler: Read Param of Method[%s] returns error %v", requestCodec.Method(), pErr)) logging.Logger().Errorf("RPC Servlet Handler: Read Param of Method[%s] returns error %v", requestCodec.Method(), pErr)
} else { } else {
logging.Logger().Error(fmt.Sprintf("RPC Servlet Handler: Method[%s] params[%v] returns error %v", requestCodec.Method(), params, err)) logging.Logger().Errorf("RPC Servlet Handler: Method[%s] params[%v] returns error %v", requestCodec.Method(), params, err)
} }
} }
@ -40,6 +40,6 @@ func (sh *ServletHandlers) Validate() {
sh.ServletHandlers.Validate() sh.ServletHandlers.Validate()
if nil == sh.RPCInvoker { if nil == sh.RPCInvoker {
logging.Logger().Panic(fmt.Sprintf("RPC Servlet Handler: RPC Invoker must be specified")) logging.Logger().Panicf("RPC Servlet Handler: RPC Invoker must be specified")
} }
} }

View File

@ -72,7 +72,7 @@ func (s *rpcServlet) Start(parentCTX cuc.Context, conn interface{}, doneChan cha
s.serverCodec = sc s.serverCodec = sc
if err := s.sh.Init(s.ctx); nil != err { if err := s.sh.Init(s.ctx); nil != err {
logging.Logger().Panic(fmt.Sprintf("Servlet: Initialization of servlet has been failed %v", err)) logging.Logger().Panicf("Servlet: Initialization of servlet has been failed %v", err)
} }
s.responseQueueChan = make(chan *responseState, s.sh.GetPendingResponses()) s.responseQueueChan = make(chan *responseState, s.sh.GetPendingResponses())
@ -100,7 +100,7 @@ func (s *rpcServlet) Send(method string, args ...interface{}) (err error) {
func (s *rpcServlet) Stop() { func (s *rpcServlet) Stop() {
if s.stopChan == nil { if s.stopChan == nil {
logging.Logger().Warn("Server: server must be started before stopping it") logging.Logger().Warnf("Server: server must be started before stopping it")
return return
} }
close(s.stopChan) close(s.stopChan)
@ -113,13 +113,13 @@ func (s *rpcServlet) Stop() {
s.conn = nil s.conn = nil
s.serverCodec = nil s.serverCodec = nil
logging.Logger().Info(fmt.Sprintf("Servlet is stopped")) logging.Logger().Infof("Servlet is stopped")
} }
func handleServlet(s *rpcServlet) { func handleServlet(s *rpcServlet) {
var err error var err error
logging.Logger().Info(fmt.Sprintf("Servlet is started")) logging.Logger().Infof("Servlet is started")
defer func() { defer func() {
s.stopWg.Done() s.stopWg.Done()
@ -148,16 +148,16 @@ func handleServlet(s *rpcServlet) {
} }
if err != nil { if err != nil {
logging.Logger().Error(fmt.Sprintf("RPC Server: servlet error %v", err)) logging.Logger().Errorf("RPC Server: servlet error %v", err)
} }
} }
func handleReader(s *rpcServlet, stopChan chan struct{}, doneChan chan error) { func handleReader(s *rpcServlet, stopChan chan struct{}, doneChan chan error) {
logging.Logger().Debug(fmt.Sprintf("reader of Servlet is started")) logging.Logger().Debugf("reader of Servlet is started")
var err error var err error
defer func() { defer func() {
logging.Logger().Debug(fmt.Sprintf("reader of Servlet is stopped")) logging.Logger().Debugf("reader of Servlet is stopped")
if r := recover(); r != nil { if r := recover(); r != nil {
if err == nil { if err == nil {
@ -179,7 +179,7 @@ func handleReader(s *rpcServlet, stopChan chan struct{}, doneChan chan error) {
err = fmt.Errorf("RPC Server: disconnected from client") err = fmt.Errorf("RPC Server: disconnected from client")
return return
} }
logging.Logger().Error(fmt.Sprintf("RPC Server: Cannot read request: [%s]", err)) logging.Logger().Errorf("RPC Server: Cannot read request: [%s]", err)
continue continue
} }
@ -196,11 +196,11 @@ func handleReader(s *rpcServlet, stopChan chan struct{}, doneChan chan error) {
} }
func handleWriter(s *rpcServlet, stopChan chan struct{}, doneChan chan error) { func handleWriter(s *rpcServlet, stopChan chan struct{}, doneChan chan error) {
logging.Logger().Debug(fmt.Sprintf("writer of Servlet is started")) logging.Logger().Debugf("writer of Servlet is started")
var err error var err error
defer func() { defer func() {
logging.Logger().Debug(fmt.Sprintf("writer of Servlet is stopped")) logging.Logger().Debugf("writer of Servlet is stopped")
if r := recover(); r != nil { if r := recover(); r != nil {
if err == nil { if err == nil {
err = fmt.Errorf("RPC Server: Panic when writing response to client: %v", r) err = fmt.Errorf("RPC Server: Panic when writing response to client: %v", r)
@ -233,11 +233,11 @@ func handleWriter(s *rpcServlet, stopChan chan struct{}, doneChan chan error) {
if nil != rs.requestCodec { if nil != rs.requestCodec {
if err := s.rwcSH.WriteResponse(s.ctx, s.conn, rs.requestCodec, rs.result, rs.err); nil != err { if err := s.rwcSH.WriteResponse(s.ctx, s.conn, rs.requestCodec, rs.result, rs.err); nil != err {
logging.Logger().Error(fmt.Sprintf("RPC Server: response error %v", err)) logging.Logger().Errorf("RPC Server: response error %v", err)
} }
} else { } else {
if err := s.rwcSH.WriteNotification(s.ctx, s.conn, s.serverCodec, rs.noti.method, rs.noti.args); nil != err { if err := s.rwcSH.WriteNotification(s.ctx, s.conn, s.serverCodec, rs.noti.method, rs.noti.args); nil != err {
logging.Logger().Error(fmt.Sprintf("RPC Server: notification error %v", err)) logging.Logger().Errorf("RPC Server: notification error %v", err)
} }
} }