Skip to content

Commit 10b1283

Browse files
author
侯锐
committed
优化日志打印
1 parent 651edcb commit 10b1283

5 files changed

Lines changed: 10 additions & 9 deletions

File tree

dubbo/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from dubbo.common.util import parse_url, get_pid, get_ip
1313
from dubbo.connection.connections import connection_pool
1414

15-
logger = logging.getLogger('dubbo')
15+
logger = logging.getLogger('python-dubbo')
1616

1717

1818
class DubboClient(object):

dubbo/common/loggers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def init_log():
4040
初始化dubbo的日志配置
4141
:return:
4242
"""
43-
logger = logging.getLogger('dubbo')
43+
logger = logging.getLogger('python-dubbo')
4444
console_handler = logging.StreamHandler(sys.stdout)
4545
formatter = MyFormatter(
4646
'%(asctime)s %(levelname)s \033[35m%(process)-5d\033[0m --- [%(threadName)15s] \033[33m%(lineno)-4d\033[0m \033[36m%(filename)s\033[0m: %(message)s')

dubbo/common/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import logging
1010

11-
logger = logging.getLogger('dubbo')
11+
logger = logging.getLogger('python-dubbo')
1212

1313
ip = None
1414
heartbeat_id = 0

dubbo/connection/connections.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from dubbo.common.exceptions import DubboResponseException, DubboRequestTimeoutException
1414
from dubbo.common.util import get_invoke_id
1515

16-
logger = logging.getLogger('dubbo')
16+
logger = logging.getLogger('python-dubbo')
1717

1818

1919
class BaseConnectionPool(object):
@@ -65,6 +65,7 @@ def get(self, host, request_param, timeout=None):
6565
result = self.results.pop(invoke_id)
6666
if isinstance(result, Exception):
6767
logger.exception(result)
68+
logger.error('Exception {} for host {}'.format(result, host))
6869
raise result
6970
return result
7071

@@ -261,9 +262,8 @@ def _check_conn(self, host):
261262
if self.client_heartbeats[host] >= TIMEOUT_MAX_TIMES:
262263
self._new_connection(host)
263264
self.client_heartbeats[host] = 0
264-
logger.debug('{} timeout and reconnected by client'.format(host))
265-
# 关闭旧的连接
266-
conn.close()
265+
conn.close() # 关闭旧的连接
266+
logger.debug('{} timeout and reconnected by client.'.format(host))
267267

268268
# 未达到最大的超时次数,超时次数+1且发送心跳包
269269
else:
@@ -382,6 +382,7 @@ def close(self):
382382
关闭连接
383383
:return:
384384
"""
385+
logger.debug('{} closed by client.'.format(self.__host))
385386
self.__sock.shutdown(socket.SHUT_RDWR)
386387
self.__sock.close()
387388

tests/dubbo_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from dubbo.common.exceptions import DubboException
1010
from dubbo.client import DubboClient, ZkRegister
1111

12-
logger = logging.getLogger('dubbo')
12+
logger = logging.getLogger('python-dubbo')
1313

1414

1515
def pretty_print(value):
@@ -74,7 +74,7 @@ def test(self):
7474
pretty_print(dubbo.call('echo22'))
7575
pretty_print(dubbo.call('echo23'))
7676

77-
log = logging.getLogger('dubbo')
77+
log = logging.getLogger('python-dubbo')
7878
log.debug('1111')
7979
log.info('22222')
8080

0 commit comments

Comments
 (0)