@@ -1749,7 +1749,7 @@ def got_data(self):
1749
1749
def send_message (self , message , pushbuf = False ):
1750
1750
if self .state != "connected" and not pushbuf :
1751
1751
raise IOError ('Not connected, no pushbuf' )
1752
- logger . debug ( "Send message to %s:%d: %s" % ( self . dstaddr , self . dstport , repr ( message )) )
1752
+ self . _log_message ( "send" , message )
1753
1753
command = message .command
1754
1754
data = message .serialize ()
1755
1755
tmsg = self .MAGIC_BYTES [self .network ]
@@ -1771,9 +1771,19 @@ def got_message(self, message):
1771
1771
self .messagemap [b'ping' ] = msg_ping_prebip31
1772
1772
if self .last_sent + 30 * 60 < time .time ():
1773
1773
self .send_message (self .messagemap [b'ping' ]())
1774
- logger . debug ( "Received message from %s:%d: %s" % ( self . dstaddr , self . dstport , repr ( message )) )
1774
+ self . _log_message ( "receive" , message )
1775
1775
self .cb .deliver (self , message )
1776
1776
1777
+ def _log_message (self , direction , msg ):
1778
+ if direction == "send" :
1779
+ log_message = "Send message to "
1780
+ elif direction == "receive" :
1781
+ log_message = "Received message from "
1782
+ log_message += "%s:%d: %s" % (self .dstaddr , self .dstport , repr (msg )[:500 ])
1783
+ if len (log_message ) > 500 :
1784
+ log_message += "... (msg truncated)"
1785
+ logger .debug (log_message )
1786
+
1777
1787
def disconnect_node (self ):
1778
1788
self .disconnect = True
1779
1789
0 commit comments