luckytaxi luckytaxi - 4 years ago 218
Python Question

How to disable INFO logging from a third party module in Python

I'm querying a Serf cluster using Python but I would like to suppress the

INFO
data that comes from Serf. I've tried to override it so that it will only print
WARNING
messages but it refuses to honor it.

Output:



01-04 14:57 root INFO Connecting to cluster
01-04 14:57 serf-rpc-client INFO will connect to [('myhost.localdomain.local', 7373, {})]
01-04 14:57 serf-rpc-client INFO trying to connect to myhost.localdomain.local:7373
01-04 14:57 serf-rpc-client INFO connected to myhost.localdomain.local:7373
01-04 14:57 serf-rpc-client INFO trying to request command: <RequestHandshake: handshake, 0, {'Version': 1}>
01-04 14:57 serf-rpc-client INFO trying to request command: <RequestAuth: auth, 1, {'AuthKey': 'thundercats'}>
01-04 14:57 serf-rpc-client INFO trying to request command: <RequestMembers: members, 2, {'Status': 'failed'}>
01-04 14:57 serf-rpc-client INFO successfully handshaked
01-04 14:57 serf-rpc-client INFO successfully authed
01-04 14:57 root INFO myhost123.localdomain.local has left the cluster


Logging Code



logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
filename='/var/log/ocd_watcher.log',
filemode='w')

serf_logger = logging.getLogger('serf')
serf_logger.setLevel(logging.WARNING)

console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(default_formatter)

logger = logging.getLogger()
logger.addHandler(console_handler)
logger.addHandler(serf_logger)

Answer Source

The logger name is serf-rpc-client so this should work

serf_logger = logging.getLogger('serf-rpc-client')
serf_logger.setLevel(logging.WARNING)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download