Skip to content

Commit b250add

Browse files
committed
using python logging in Client instead of print
1 parent 682d2d1 commit b250add

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

Client.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1+
import logging
12
import socket
2-
from datetime import datetime
33
from threading import Thread, RLock, Event
44

55
from mprotocol_client_python.ProtocolResult import ProtocolResult
66
from mprotocol_client_python.NodeProperty import NodeProperty
77

88

9-
def DEBUG_PRINT(message):
10-
print('[%s] %s' % (datetime.now().strftime('%H:%M:%S'), message))
11-
12-
139
## MProtocol client class
1410
#
1511
# Manages connection to the remote device and is the interface for data exchange
@@ -128,7 +124,7 @@ def remove_subscription(self, callback, node_path, property_name=None):
128124

129125
## Background thread that handles incoming traffic
130126
def thread_function(self):
131-
DEBUG_PRINT('starting thread')
127+
logging.info('Starting client thread')
132128
while True:
133129
try:
134130
received_bytes = self.socket.recv(4096)
@@ -137,11 +133,11 @@ def thread_function(self):
137133
self.process_received_str()
138134
else:
139135
# recv() returns empty string if the remote side has closed the connection
140-
DEBUG_PRINT('finishing thread (empty recv)')
136+
logging.info('Finishing thread (server closed)')
141137
break
142138
except Exception as e:
143139
# remote side will not be sending more data after connection errors
144-
DEBUG_PRINT('finishing thread (exception:%s)' % str(e))
140+
logging.error('Finishing thread (exception:%s)' % str(e))
145141
break
146142

147143
# close and delete socket so that it won't be used again
@@ -181,7 +177,7 @@ def process_received_str(self):
181177
self.result = ProtocolResult(ProtocolResult.ok_init_str, line[4:])
182178
self.response_received_or_error.set()
183179
else:
184-
DEBUG_PRINT('Unable to process response: ' + line)
180+
logging.warning('Unable to process response: ' + line)
185181

186182
# keep last unfinished line in buffer
187183
self.received_str = lines[-1]

0 commit comments

Comments
 (0)