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) {
|
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()
|
||||||
if nil == sh {
|
if nil == sh {
|
||||||
logging.Logger().Panic("Client Socket: SocketHandler must be specified")
|
logging.Logger().Panicf("Client Socket: SocketHandler must be specified")
|
||||||
}
|
}
|
||||||
sh.Validate()
|
sh.Validate()
|
||||||
|
|
||||||
|
|
|
@ -71,14 +71,14 @@ func (sb *SocketBuilders) GetLocalAddress() net.Addr {
|
||||||
|
|
||||||
func (sb *SocketBuilders) Validate() {
|
func (sb *SocketBuilders) Validate() {
|
||||||
if nil == sb.SocketHandler {
|
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 {
|
if "" == sb.Network {
|
||||||
logging.Logger().Panic("Client Socket: Network must be specified")
|
logging.Logger().Panicf("Client Socket: Network must be specified")
|
||||||
}
|
}
|
||||||
if "" == sb.Address {
|
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 {
|
if 0 >= sb.KeepAlive {
|
||||||
|
|
12
server.go
12
server.go
|
@ -75,7 +75,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 {
|
||||||
|
@ -85,7 +85,7 @@ func (s *server) Context() ServerContext {
|
||||||
func handleServer(s *server) {
|
func handleServer(s *server) {
|
||||||
defer s.stopWg.Done()
|
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)
|
s.sh.OnStart(s.ctx)
|
||||||
|
|
||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
|
@ -97,7 +97,7 @@ func handleServer(s *server) {
|
||||||
go func() {
|
go func() {
|
||||||
if conn, err = s.listener.Accept(); err != nil {
|
if conn, err = s.listener.Accept(); err != nil {
|
||||||
if stopping.Load() == 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)
|
close(acceptChan)
|
||||||
|
@ -128,12 +128,12 @@ func handleServer(s *server) {
|
||||||
socketCTX := socketHandler.SocketContext(s.ctx)
|
socketCTX := socketHandler.SocketContext(s.ctx)
|
||||||
|
|
||||||
if socketID = socketHandler.Handshake(socketCTX, conn); "" == socketID {
|
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()
|
conn.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
@ -158,7 +158,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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ func (sh *ServerHandlers) OnStart(serverCTX ServerContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *ServerHandlers) OnError(serverCTX ServerContext, conn net.Conn, status int, reason error) {
|
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
|
// OnStop invoked when server is stopped
|
||||||
|
@ -62,6 +62,6 @@ func (sh *ServerHandlers) GetSocketHandler() SocketHandler {
|
||||||
|
|
||||||
func (sh *ServerHandlers) Validate() {
|
func (sh *ServerHandlers) Validate() {
|
||||||
if nil == sh.SocketHandler {
|
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