Skip to content

Commit 2cf6b2f

Browse files
committed
Merge pull request #17 from mosquito/master
logging with logging
2 parents b15bf91 + b19db7f commit 2cf6b2f

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

tornado_mysql/pools.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from collections import deque
55
import warnings
6+
import logging
67

78
from tornado.ioloop import IOLoop
89
from tornado.gen import coroutine, Return
@@ -12,12 +13,7 @@
1213
from tornado_mysql.connections import Connection
1314

1415

15-
DEBUG = False
16-
17-
18-
def _debug(*msg):
19-
if DEBUG:
20-
print(*msg)
16+
log = logging.getLogger("tornado_mysql.pools")
2117

2218

2319
class Pool(object):
@@ -67,15 +63,15 @@ def _get_conn(self):
6763
if now - conn.connected_time > self.max_recycle_sec:
6864
self._close_async(conn)
6965
continue
70-
_debug("Reusing connection from pool:", self.stat())
66+
log.debug("Reusing connection from pool: %s", self.stat())
7167
fut = Future()
7268
fut.set_result(conn)
7369
return fut
7470

7571
# Open new connection
7672
if self.max_open == 0 or self._opened_conns < self.max_open:
7773
self._opened_conns += 1
78-
_debug("Creating new connection:", self.stat())
74+
log.debug("Creating new connection: %s", self.stat())
7975
return connect(**self.connect_kwargs)
8076

8177
# Wait to other connection is released.
@@ -89,10 +85,10 @@ def _put_conn(self, conn):
8985
if self._waitings:
9086
fut = self._waitings.popleft()
9187
fut.set_result(conn)
92-
_debug("Passing returned connection to waiter:", self.stat())
88+
log.debug("Passing returned connection to waiter: %s", self.stat())
9389
else:
9490
self._free_conn.append(conn)
95-
_debug("Add conn to free pool:", self.stat())
91+
log.debug("Add conn to free pool: %s", self.stat())
9692
else:
9793
self._close_async(conn)
9894

@@ -111,7 +107,7 @@ def _after_close(self, fut=None):
111107
self.io_loop.add_future(cf, callback=lambda f: fut.set_result(conn))
112108
else:
113109
self._opened_conns -= 1
114-
_debug("Connection closed:", self.stat())
110+
log.debug("Connection closed: %s", self.stat())
115111

116112
@coroutine
117113
def execute(self, query, params=None):
@@ -194,4 +190,5 @@ def rollback(self):
194190
def __del__(self):
195191
if self._pool is not None:
196192
warnings.warn("Transaction has not committed or rollbacked.")
193+
log.warn("Transaction has not committed or rollbacked.")
197194
self._pool._close_conn(self._conn)

0 commit comments

Comments
 (0)