From cf11393021f50e6e3c027dc03324b842d4b788d0 Mon Sep 17 00:00:00 2001 From: geek Date: Wed, 21 Mar 2018 20:07:11 +0900 Subject: [PATCH] logging method modify --- client/socket.go | 6 +++--- client/socket_builders.go | 6 +++--- server.go | 12 ++++++------ server_handlers.go | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/client/socket.go b/client/socket.go index f9e26e3..c896f32 100644 --- a/client/socket.go +++ b/client/socket.go @@ -17,18 +17,18 @@ type Socket interface { func NewSocket(sb SocketBuilder, parentContext cuc.Context) (Socket, error) { if nil == sb { - logging.Logger().Panic("Client Socket: SocketBuilder must be specified") + logging.Logger().Panicf("Client Socket: SocketBuilder must be specified") } sb.Validate() sc := sb.SocketContext(parentContext) if nil == sc { - logging.Logger().Panic("Client Socket: SocketContext must be specified") + logging.Logger().Panicf("Client Socket: SocketContext must be specified") } sh := sb.GetSocketHandler() if nil == sh { - logging.Logger().Panic("Client Socket: SocketHandler must be specified") + logging.Logger().Panicf("Client Socket: SocketHandler must be specified") } sh.Validate() diff --git a/client/socket_builders.go b/client/socket_builders.go index d53cee6..a2731a1 100644 --- a/client/socket_builders.go +++ b/client/socket_builders.go @@ -71,14 +71,14 @@ func (sb *SocketBuilders) GetLocalAddress() net.Addr { func (sb *SocketBuilders) Validate() { if nil == sb.SocketHandler { - logging.Logger().Panic("Client Socket: SocketHandler must be specified") + logging.Logger().Panicf("Client Socket: SocketHandler must be specified") } if "" == sb.Network { - logging.Logger().Panic("Client Socket: Network must be specified") + logging.Logger().Panicf("Client Socket: Network must be specified") } if "" == sb.Address { - logging.Logger().Panic("Client Socket: Address must be specified") + logging.Logger().Panicf("Client Socket: Address must be specified") } if 0 >= sb.KeepAlive { diff --git a/server.go b/server.go index 8fc1409..9a46b80 100644 --- a/server.go +++ b/server.go @@ -75,7 +75,7 @@ func (s *server) Stop() { s.sh.OnStop(s.ctx) - logging.Logger().Info(fmt.Sprintf("Server[%s] is stopped", s.sh.GetName())) + logging.Logger().Infof("Server[%s] is stopped", s.sh.GetName()) } func (s *server) Context() ServerContext { @@ -85,7 +85,7 @@ func (s *server) Context() ServerContext { func handleServer(s *server) { defer s.stopWg.Done() - logging.Logger().Info(fmt.Sprintf("Server[%s] is started", s.sh.GetName())) + logging.Logger().Infof("Server[%s] is started", s.sh.GetName()) s.sh.OnStart(s.ctx) var conn net.Conn @@ -97,7 +97,7 @@ func handleServer(s *server) { go func() { if conn, err = s.listener.Accept(); err != nil { if stopping.Load() == nil { - logging.Logger().Error(fmt.Sprintf("Server: Cannot accept new connection: [%s]", err)) + logging.Logger().Errorf("Server: Cannot accept new connection: [%s]", err) } } close(acceptChan) @@ -128,12 +128,12 @@ func handleServer(s *server) { socketCTX := socketHandler.SocketContext(s.ctx) if socketID = socketHandler.Handshake(socketCTX, conn); "" == socketID { - logging.Logger().Error(fmt.Sprintf("Server: Handshake err addr[%s] %v", conn.RemoteAddr(), conn)) + logging.Logger().Errorf("Server: Handshake err addr[%s] %v", conn.RemoteAddr(), conn) conn.Close() continue } soc := newSocket(socketHandler, socketCTX, conn, socketID) - logging.Logger().Debug(fmt.Sprintf("Server: Client[%s] is connected.", soc.RemoteAddr())) + logging.Logger().Debugf("Server: Client[%s] is connected.", soc.RemoteAddr()) socketHandler.addSocket(soc) socketHandler.OnConnect(soc) @@ -158,7 +158,7 @@ func handleConnection(s *server, soc Socket, socketHandler SocketHandler) { case <-handleDoneChan: close(clientStopChan) socketHandler.OnDisconnect(soc) - logging.Logger().Debug(fmt.Sprintf("Server: Client[%s] is disconnected.", soc.RemoteAddr())) + logging.Logger().Debugf("Server: Client[%s] is disconnected.", soc.RemoteAddr()) socketHandler.removeSocket(soc) soc.Close() } diff --git a/server_handlers.go b/server_handlers.go index 779c02a..7261db3 100644 --- a/server_handlers.go +++ b/server_handlers.go @@ -43,7 +43,7 @@ func (sh *ServerHandlers) OnStart(serverCTX ServerContext) { } func (sh *ServerHandlers) OnError(serverCTX ServerContext, conn net.Conn, status int, reason error) { - logging.Logger().Error(fmt.Sprintf("Server: error status: %d, reason: %v, [%v]", status, reason, conn)) + logging.Logger().Errorf("Server: error status: %d, reason: %v, [%v]", status, reason, conn) } // OnStop invoked when server is stopped @@ -62,6 +62,6 @@ func (sh *ServerHandlers) GetSocketHandler() SocketHandler { func (sh *ServerHandlers) Validate() { if nil == sh.SocketHandler { - panic("Server: SocketHandler must be specified") + logging.Logger().Panicf("Server: SocketHandler must be specified") } }