summaryrefslogtreecommitdiff
path: root/redis/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'redis/client.py')
-rw-r--r--redis/client.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/redis/client.py b/redis/client.py
index 81e977c..93607d0 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -58,7 +58,8 @@ class Connection(object):
"Connects to the Redis server if not already connected"
if self._sock:
return
- log.debug("connecting to %s:%d/%d", self.host, self.port, self.db)
+ if log_enabled(log):
+ log.debug("connecting to %s:%d/%d", self.host, self.port, self.db)
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(self.socket_timeout)
@@ -82,7 +83,8 @@ class Connection(object):
"Disconnects from the Redis server"
if self._sock is None:
return
- log.debug("disconnecting from %s:%d/%d", self.host, self.port, self.db)
+ if log_enabled(log):
+ log.debug("disconnecting from %s:%d/%d", self.host, self.port, self.db)
try:
self._sock.close()
except socket.error:
@@ -161,6 +163,9 @@ def dict_merge(*dicts):
[merged.update(d) for d in dicts]
return merged
+def log_enabled(log, level=logging.DEBUG):
+ return log.isEnabledFor(log, level)
+
def repr_command(args):
"Represents a command as a string."
command = [args[0]]
@@ -338,7 +343,8 @@ class Redis(threading.local):
if self.subscribed and not subscription_command:
raise RedisError("Cannot issue commands other than SUBSCRIBE and "
"UNSUBSCRIBE while channels are open")
- log.debug(repr_command(command))
+ if log_enabled(log):
+ log.debug(repr_command(command))
command = self._encode_command(command)
try:
self.connection.send(command, self)
@@ -1438,7 +1444,7 @@ class Pipeline(Redis):
commands,
(('', ('EXEC',), ''),)
)])
- if log.isEnabledFor(logging.DEBUG):
+ if log_enabled(log):
log.debug("MULTI")
for command in commands:
log.debug("TRANSACTION> "+ repr_command(command[1]))
@@ -1468,7 +1474,7 @@ class Pipeline(Redis):
def _execute_pipeline(self, commands):
# build up all commands into a single request to increase network perf
all_cmds = ''.join([self._encode_command(c) for _1, c, _2 in commands])
- if log.isEnabledFor(logging.DEBUG):
+ if log_enabled(log):
for command in commands:
log.debug("PIPELINE> " + repr_command(command[1]))
self.connection.send(all_cmds, self)