From 1fdb4da43725843b048a537831cdad1b2eca49eb Mon Sep 17 00:00:00 2001 From: Xiang Wang Date: Sat, 21 Dec 2024 10:17:55 +0800 Subject: [PATCH] log: use environment to control the log level --- channels_redis/core.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/channels_redis/core.py b/channels_redis/core.py index a230081..058712d 100644 --- a/channels_redis/core.py +++ b/channels_redis/core.py @@ -3,6 +3,7 @@ import functools import itertools import logging +import os import time import uuid @@ -21,6 +22,7 @@ ) logger = logging.getLogger(__name__) +OVER_CAPACITY_LEVEL = int(os.environ.get("CHANNELS_REDIS_CAPACITY_LOG_LEVEL", 10)) class ChannelLock: @@ -574,7 +576,8 @@ async def group_send(self, group, message): group_send_lua, len(channel_redis_keys), *channel_redis_keys, *args ) if channels_over_capacity > 0: - logger.info( + logger.log( + OVER_CAPACITY_LEVEL, "%s of %s channels over capacity in group %s", channels_over_capacity, len(channel_names), @@ -596,9 +599,9 @@ def _map_channel_keys_to_connection(self, channel_names, message): # Connection dict keyed by index to list of redis keys mapped on that index connection_to_channel_keys = collections.defaultdict(list) # Message dict maps redis key to the message that needs to be send on that key - channel_key_to_message = dict() + channel_key_to_message = {} # Channel key mapped to its capacity - channel_key_to_capacity = dict() + channel_key_to_capacity = {} # For each channel for channel in channel_names: