4

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)
2
  • So you want to get INFO messages from other things but not serf?
    – jonrsharpe
    Jan 4, 2016 at 20:07
  • yeah, i actually figured it out a few minutes later while waiting for an answer.
    – sdot257
    Jan 4, 2016 at 20:09

1 Answer 1

4

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

serf_logger = logging.getLogger('serf-rpc-client')
serf_logger.setLevel(logging.WARNING)
4
  • Yeah I figured it out afterwars by looking at the source - duh! Is there a quicker way to know this?
    – sdot257
    Jan 4, 2016 at 20:08
  • 2
    Reading the log - 01-04 14:57 serf-rpc-client INFO - the first is date, then the logger name and finally the level. If the question helps,
    – masnun
    Jan 4, 2016 at 20:09
  • Ah ok i did notice that. Thanks a lot.
    – sdot257
    Jan 4, 2016 at 20:09
  • I will, it wont let me. I have to wait. :-)
    – sdot257
    Jan 4, 2016 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.