From 3e7ee505b40c53ba9e1e480a8cb266c8ddd31f43 Mon Sep 17 00:00:00 2001 From: geek Date: Wed, 21 Mar 2018 20:11:48 +0900 Subject: [PATCH] logging method modify --- client/socket.go | 4 ++-- client/socket_builders.go | 2 +- server.go | 14 +++++++------- server_handlers.go | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/client/socket.go b/client/socket.go index 515d430..7414f65 100644 --- a/client/socket.go +++ b/client/socket.go @@ -143,13 +143,13 @@ 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() diff --git a/client/socket_builders.go b/client/socket_builders.go index 20d4c3e..d80a509 100644 --- a/client/socket_builders.go +++ b/client/socket_builders.go @@ -87,7 +87,7 @@ func (sb *SocketBuilders) GetWriteBufferSize() int { func (sb *SocketBuilders) Validate() { if nil == sb.SocketHandler { - logging.Logger().Panic("Websocket Fasthttp: SocketHandler must be specified") + logging.Logger().Panicf("Websocket Fasthttp: SocketHandler must be specified") } sb.SocketHandler.Validate() diff --git a/server.go b/server.go index e0b035a..3ffe49f 100644 --- a/server.go +++ b/server.go @@ -42,7 +42,7 @@ type server struct { func (s *server) Start() error { if nil == s.sh { - logging.Logger().Panic("Server: server handler must be specified.") + logging.Logger().Panicf("Server: server handler must be specified.") } s.sh.Validate() @@ -92,7 +92,7 @@ func (s *server) Start() error { func (s *server) Stop() { 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 } close(s.stopChan) @@ -101,7 +101,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 { @@ -114,11 +114,11 @@ func handleServer(s *server) { defer s.stopWg.Done() if err := s.httpServer.Serve(s.listener); nil != err { - logging.Logger().Error(fmt.Sprintf("Server: Server err - %v", err)) + logging.Logger().Errorf("Server: Server err - %v", err) } }() - 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) select { @@ -154,7 +154,7 @@ func (s *server) handleRequest(ctx *fasthttp.RequestCtx) { } 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) @@ -186,7 +186,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 9aed952..1600695 100644 --- a/server_handlers.go +++ b/server_handlers.go @@ -86,7 +86,7 @@ func (sh *ServerHandlers) CheckOrigin(ctx *fasthttp.RequestCtx) bool { } func (sh *ServerHandlers) OnError(serverCTX ServerContext, ctx *fasthttp.RequestCtx, status int, reason error) { - logging.Logger().Error(fmt.Sprintf("Server: error status: %d, reason: %v, [%v]", status, reason, ctx)) + logging.Logger().Errorf("Server: error status: %d, reason: %v, [%v]", status, reason, ctx) } // OnStop invoked when server is stopped