@@ -58,7 +58,8 @@ def connect(self, redis_instance):
58
58
"Connects to the Redis server if not already connected"
59
59
if self ._sock :
60
60
return
61
- log .debug ("connecting to %s:%d/%d" , self .host , self .port , self .db )
61
+ if log_enabled (log ):
62
+ log .debug ("connecting to %s:%d/%d" , self .host , self .port , self .db )
62
63
try :
63
64
sock = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
64
65
sock .settimeout (self .socket_timeout )
@@ -82,7 +83,8 @@ def disconnect(self):
82
83
"Disconnects from the Redis server"
83
84
if self ._sock is None :
84
85
return
85
- log .debug ("disconnecting from %s:%d/%d" , self .host , self .port , self .db )
86
+ if log_enabled (log ):
87
+ log .debug ("disconnecting from %s:%d/%d" , self .host , self .port , self .db )
86
88
try :
87
89
self ._sock .close ()
88
90
except socket .error :
@@ -161,6 +163,9 @@ def dict_merge(*dicts):
161
163
[merged .update (d ) for d in dicts ]
162
164
return merged
163
165
166
+ def log_enabled (log , level = logging .DEBUG ):
167
+ return log .isEnabledFor (log , level )
168
+
164
169
def repr_command (args ):
165
170
"Represents a command as a string."
166
171
command = [args [0 ]]
@@ -338,7 +343,8 @@ def _execute_command(self, command_name, command, **options):
338
343
if self .subscribed and not subscription_command :
339
344
raise RedisError ("Cannot issue commands other than SUBSCRIBE and "
340
345
"UNSUBSCRIBE while channels are open" )
341
- log .debug (repr_command (command ))
346
+ if log_enabled (log ):
347
+ log .debug (repr_command (command ))
342
348
command = self ._encode_command (command )
343
349
try :
344
350
self .connection .send (command , self )
@@ -1438,7 +1444,7 @@ def _execute_transaction(self, commands):
1438
1444
commands ,
1439
1445
(('' , ('EXEC' ,), '' ),)
1440
1446
)])
1441
- if log . isEnabledFor ( logging . DEBUG ):
1447
+ if log_enabled ( log ):
1442
1448
log .debug ("MULTI" )
1443
1449
for command in commands :
1444
1450
log .debug ("TRANSACTION> " + repr_command (command [1 ]))
@@ -1468,7 +1474,7 @@ def _execute_transaction(self, commands):
1468
1474
def _execute_pipeline (self , commands ):
1469
1475
# build up all commands into a single request to increase network perf
1470
1476
all_cmds = '' .join ([self ._encode_command (c ) for _1 , c , _2 in commands ])
1471
- if log . isEnabledFor ( logging . DEBUG ):
1477
+ if log_enabled ( log ):
1472
1478
for command in commands :
1473
1479
log .debug ("PIPELINE> " + repr_command (command [1 ]))
1474
1480
self .connection .send (all_cmds , self )
0 commit comments