Skip to content

Commit b6b2fee

Browse files
committed
Changing the maint notifications logging strategy - to use named logger instead of directly the logging module.
1 parent 8db51bb commit b6b2fee

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

redis/maint_notifications.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
if TYPE_CHECKING:
1313
from redis.cluster import MaintNotificationsAbstractRedisCluster
1414

15+
logger = logging.getLogger(__name__)
16+
1517

1618
class MaintenanceState(enum.Enum):
1719
NONE = "none"
@@ -573,7 +575,7 @@ def add_debug_log_for_notification(
573575
connection: "MaintNotificationsAbstractConnection",
574576
notification: Union[str, MaintenanceNotification],
575577
):
576-
if logging.getLogger().isEnabledFor(logging.DEBUG):
578+
if logger.isEnabledFor(logging.DEBUG):
577579
socket_address = None
578580
try:
579581
socket_address = (
@@ -583,7 +585,7 @@ def add_debug_log_for_notification(
583585
except (AttributeError, OSError):
584586
pass
585587

586-
logging.debug(
588+
logger.debug(
587589
f"Handling maintenance notification: {notification}, "
588590
f"with connection: {connection}, connected to ip {connection.get_resolved_ip()}, "
589591
f"local socket port: {socket_address}",
@@ -747,7 +749,7 @@ def handle_notification(self, notification: MaintenanceNotification):
747749
if isinstance(notification, NodeMovingNotification):
748750
return self.handle_node_moving_notification(notification)
749751
else:
750-
logging.error(f"Unhandled notification type: {notification}")
752+
logger.error(f"Unhandled notification type: {notification}")
751753

752754
def handle_node_moving_notification(self, notification: NodeMovingNotification):
753755
if (
@@ -763,7 +765,7 @@ def handle_node_moving_notification(self, notification: NodeMovingNotification):
763765
return
764766

765767
with self.pool._lock:
766-
logging.debug(
768+
logger.debug(
767769
f"Handling node MOVING notification: {notification}, "
768770
f"with connection: {self.connection}, connected to ip "
769771
f"{self.connection.get_resolved_ip() if self.connection else None}"
@@ -871,7 +873,7 @@ def handle_node_moved_notification(self, notification: NodeMovingNotification):
871873
notification_hash = hash(notification)
872874

873875
with self._lock:
874-
logging.debug(
876+
logger.debug(
875877
f"Reverting temporary changes related to notification: {notification}, "
876878
f"with connection: {self.connection}, connected to ip "
877879
f"{self.connection.get_resolved_ip() if self.connection else None}"
@@ -940,7 +942,7 @@ def handle_notification(self, notification: MaintenanceNotification):
940942
notification_type = self._NOTIFICATION_TYPES.get(notification.__class__, None)
941943

942944
if notification_type is None:
943-
logging.error(f"Unhandled notification type: {notification}")
945+
logger.error(f"Unhandled notification type: {notification}")
944946
return
945947

946948
if notification_type:
@@ -1023,7 +1025,7 @@ def handle_notification(self, notification: MaintenanceNotification):
10231025
if isinstance(notification, OSSNodeMigratedNotification):
10241026
self.handle_oss_maintenance_completed_notification(notification)
10251027
else:
1026-
logging.error(f"Unhandled notification type: {notification}")
1028+
logger.error(f"Unhandled notification type: {notification}")
10271029

10281030
def handle_oss_maintenance_completed_notification(
10291031
self, notification: OSSNodeMigratedNotification
@@ -1042,7 +1044,7 @@ def handle_oss_maintenance_completed_notification(
10421044
# process the same notification twice
10431045
return
10441046

1045-
logging.debug(f"Handling SMIGRATED notification: {notification}")
1047+
logger.debug(f"Handling SMIGRATED notification: {notification}")
10461048
self._in_progress.add(notification)
10471049

10481050
# Extract the information about the src and destination nodes that are affected

0 commit comments

Comments
 (0)