Grokzen / redis-py-cluster

Python cluster client for the official redis cluster. Redis 3.0+.
https://redis-py-cluster.readthedocs.io/
MIT License
1.1k stars 316 forks source link

Turn off vervose logging #511

Closed iDataist closed 1 year ago

iDataist commented 1 year ago

I used the code below but it does not impact the verbose logging. Is there a way to turn the vervose logging off?

from rediscluster import RedisCluster
import logging
logging.getLogger("rediscluster.connection").setLevel(logging.ERROR)
redis = RedisCluster(startup_nodes=[{"host": "clustercfg.*****.*****.usw2.cache.amazonaws.com","port": "6379"}], 
                     decode_responses=True,
                     skip_full_coverage_check=True,
                     ssl=True,
                     username="default",
                     password="****",)

if redis.ping():
    logging.info("Connected to Redis")

The log looks like this:

INFO:rediscluster.client:Created new instance of RedisCluster client instance
INFO:rediscluster.client:Patching connection_class to SSLClusterConnection
INFO:rediscluster.client:Using ClusterConnectionPool
INFO:root:Connected to Redis

Versions:

redis==3.5.3
redis-py-cluster==2.1.3
Grokzen commented 1 year ago

By default we only add a Nulllogger to the package level here https://github.com/Grokzen/redis-py-cluster/blob/master/rediscluster/__init__.py#L58 anything outside of that would have to be on your end.

Are you sure you dont have to configure your logger before importing rediscluster to get the config setup properly?

I think you have to really inspect each logger with pdb where the log events happen and see why your loggers default to INFO. But also note that you have only set logging level to ERROr for the rediscluster.connection instance and not the rediscluster.client instance where your log messages comes from

iDataist commented 1 year ago

Hi @Grokzen, I truly appreicate your fast response. I incorporated your advice and moved importing rediscluster after configuring the logging. Below is the code that worked. Thank you!

import logging
logging.getLogger("rediscluster.connection").setLevel(logging.ERROR)

from rediscluster import RedisCluster
redis = RedisCluster(startup_nodes=[{"host": "clustercfg.*****.*****.usw2.cache.amazonaws.com","port": "6379"}], 
                     decode_responses=True,
                     skip_full_coverage_check=True,
                     ssl=True,
                     username="default",
                     password="****",)

if redis.ping():
    logging.info("Connected to Redis")
Grokzen commented 1 year ago

I have no idea really why logging behaves like this but I remember it being like that. I guess it depends on the object create order because the log object within the file is created before and then it gets whatever config is at that point in time. I also always have been under the impression that python logging used singleton global objects for loggers and updating one would set it for everything and all created logger objects already present.

iDataist commented 1 year ago

I was not aware of this behavior. Thanks again for sharing your knowledge on this, @Grokzen!