sdot257
sdot257

Reputation: 10366

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)

Upvotes: 5

Views: 4892

Answers (1)

masnun
masnun

Reputation: 11906

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

serf_logger = logging.getLogger('serf-rpc-client')
serf_logger.setLevel(logging.WARNING)

Upvotes: 5

Related Questions