logging method modify

This commit is contained in:
geek 2018-03-21 20:11:48 +09:00
parent d4a7836ef7
commit 3e7ee505b4
4 changed files with 11 additions and 11 deletions

View File

@ -143,13 +143,13 @@ type Socket interface {
func NewSocket(sb SocketBuilder, parentContext cuc.Context) (Socket, error) { func NewSocket(sb SocketBuilder, parentContext cuc.Context) (Socket, error) {
if nil == sb { if nil == sb {
logging.Logger().Panic("Client Socket: SocketBuilder must be specified") logging.Logger().Panicf("Client Socket: SocketBuilder must be specified")
} }
sb.Validate() sb.Validate()
sc := sb.SocketContext(parentContext) sc := sb.SocketContext(parentContext)
if nil == sc { if nil == sc {
logging.Logger().Panic("Client Socket: SocketContext must be specified") logging.Logger().Panicf("Client Socket: SocketContext must be specified")
} }
sh := sb.GetSocketHandler() sh := sb.GetSocketHandler()

View File

@ -87,7 +87,7 @@ func (sb *SocketBuilders) GetWriteBufferSize() int {
func (sb *SocketBuilders) Validate() { func (sb *SocketBuilders) Validate() {
if nil == sb.SocketHandler { 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() sb.SocketHandler.Validate()

View File

@ -42,7 +42,7 @@ type server struct {
func (s *server) Start() error { func (s *server) Start() error {
if nil == s.sh { 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() s.sh.Validate()
@ -92,7 +92,7 @@ func (s *server) Start() error {
func (s *server) Stop() { func (s *server) 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)
@ -101,7 +101,7 @@ func (s *server) Stop() {
s.sh.OnStop(s.ctx) 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 { func (s *server) Context() ServerContext {
@ -114,11 +114,11 @@ func handleServer(s *server) {
defer s.stopWg.Done() defer s.stopWg.Done()
if err := s.httpServer.Serve(s.listener); nil != err { 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) s.sh.OnStart(s.ctx)
select { select {
@ -154,7 +154,7 @@ func (s *server) handleRequest(ctx *fasthttp.RequestCtx) {
} }
soc := newSocket(socketHandler, socketCTX, conn, socketID) 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.addSocket(soc)
socketHandler.OnConnect(soc) socketHandler.OnConnect(soc)
@ -186,7 +186,7 @@ func handleConnection(s *server, soc Socket, socketHandler SocketHandler) {
case <-handleDoneChan: case <-handleDoneChan:
close(clientStopChan) close(clientStopChan)
socketHandler.OnDisconnect(soc) 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) socketHandler.removeSocket(soc)
soc.Close() soc.Close()
} }

View File

@ -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) { 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 // OnStop invoked when server is stopped