logging method modify
This commit is contained in:
parent
41382db599
commit
cf11393021
|
@ -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()
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
12
server.go
12
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()
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user