From: Jeff Halter Date: Thu, 23 Jun 2022 22:35:45 +0000 (-0700) Subject: Improve logging readability X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/commitdiff_plain/0da28a1fe47ffc60e40aeca9dddd7ab37e52a999?hp=c6a3fa2cdbf7eb78964a5df7622482cdd8782d74 Improve logging readability --- diff --git a/hotline/client.go b/hotline/client.go index 3a6584a..e5b396b 100644 --- a/hotline/client.go +++ b/hotline/client.go @@ -674,10 +674,7 @@ func (c *Client) HandleTransaction(t *Transaction) error { } requestNum := binary.BigEndian.Uint16(t.Type) - c.Logger.Infow( - "Received Transaction", - "RequestType", requestNum, - ) + c.Logger.Debugw("Received Transaction", "RequestType", requestNum) if handler, ok := c.Handlers[requestNum]; ok { outT, _ := handler.Handle(c, t) diff --git a/hotline/client_conn.go b/hotline/client_conn.go index 6a27977..1186947 100644 --- a/hotline/client_conn.go +++ b/hotline/client_conn.go @@ -78,7 +78,7 @@ func (cc *ClientConn) handleTransaction(transaction *Transaction) error { } } - cc.logger.Infow("Received Transaction", "RequestType", handler.Name) + cc.logger.Debugw("Received Transaction", "RequestType", handler.Name) transactions, err := handler.Handler(cc, transaction) if err != nil { diff --git a/hotline/server.go b/hotline/server.go index e685afd..0677a81 100644 --- a/hotline/server.go +++ b/hotline/server.go @@ -193,8 +193,9 @@ func (s *Server) Serve(ctx context.Context, ln net.Listener) error { }) go func() { + s.Logger.Infow("Connection established", "RemoteAddr", conn.RemoteAddr()) + if err := s.handleNewConnection(connCtx, conn, conn.RemoteAddr().String()); err != nil { - s.Logger.Infow("New client connection established", "RemoteAddr", conn.RemoteAddr()) if err == io.EOF { s.Logger.Infow("Client disconnected", "RemoteAddr", conn.RemoteAddr()) } else { @@ -568,6 +569,8 @@ func (s *Server) handleNewConnection(ctx context.Context, conn io.ReadWriteClose login = GuestAccount } + c.logger = s.Logger.With("remoteAddr", remoteAddr, "login", login) + // If authentication fails, send error reply and close connection if !c.Authenticate(login, encodedPassword) { t := c.NewErrReply(clientLogin, "Incorrect login.") @@ -578,7 +581,10 @@ func (s *Server) handleNewConnection(ctx context.Context, conn io.ReadWriteClose if _, err := conn.Write(b); err != nil { return err } - return fmt.Errorf("incorrect login") + + c.logger.Infow("Login failed", "clientVersion", fmt.Sprintf("%x", *c.Version)) + + return nil } if clientLogin.GetField(fieldUserName).Data != nil { @@ -595,10 +601,6 @@ func (s *Server) handleNewConnection(ctx context.Context, conn io.ReadWriteClose *c.Flags = []byte{0, 2} } - c.logger = s.Logger.With("remoteAddr", remoteAddr, "login", login) - - c.logger.Infow("Client connection received", "version", fmt.Sprintf("%x", *c.Version)) - s.outbox <- c.NewReply(clientLogin, NewField(fieldVersion, []byte{0x00, 0xbe}), NewField(fieldCommunityBannerID, []byte{0, 0}), @@ -615,6 +617,7 @@ func (s *Server) handleNewConnection(ctx context.Context, conn io.ReadWriteClose if *c.Version == nil || bytes.Equal(*c.Version, nostalgiaVersion) { c.Agreed = true c.logger = c.logger.With("name", string(c.UserName)) + c.logger.Infow("Login successful", "clientVersion", fmt.Sprintf("%x", *c.Version)) for _, t := range c.notifyOthers( *NewTransaction( diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go index 735e155..7f29d73 100644 --- a/hotline/transaction_handlers.go +++ b/hotline/transaction_handlers.go @@ -907,6 +907,7 @@ func HandleTranAgreed(cc *ClientConn, t *Transaction) (res []Transaction, err er *cc.Icon = t.GetField(fieldUserIconID).Data cc.logger = cc.logger.With("name", string(cc.UserName)) + cc.logger.Infow("Login successful", "clientVersion", fmt.Sprintf("%x", *cc.Version)) options := t.GetField(fieldOptions).Data optBitmap := big.NewInt(int64(binary.BigEndian.Uint16(options)))