Disable (or change) logging from a python module

This was an interesting one. I have been playing around with the asyncio module in Python 3.7 recently and noticed that it was injecting log messages at the INFO level, effectively spamming my logfile. Here's an example of what these messages looked like:

2019-01-21 08:04:42,559 - asyncio - INFO - poll 999.870 ms took 1002.400 ms: timeout
2019-01-21 08:04:43,574 - asyncio - INFO - poll 999.894 ms took 1000.345 ms: timeout
2019-01-21 08:04:44,590 - asyncio - INFO - poll 999.903 ms took 1000.161 ms: timeout
2019-01-21 08:04:45,608 - asyncio - INFO - poll 999.893 ms took 1003.526 ms: timeout
2019-01-21 08:04:46,627 - asyncio - INFO - poll 999.890 ms took 1002.870 ms: timeout
2019-01-21 08:04:47,643 - asyncio - INFO - poll 999.881 ms took 1000.941 ms: timeout
2019-01-21 08:04:48,661 - asyncio - INFO - poll 999.880 ms took 1002.105 ms: timeout
2019-01-21 08:04:49,675 - asyncio - INFO - poll 999.908 ms took 1000.098 ms: timeout
2019-01-21 08:04:50,691 - asyncio - INFO - poll 999.850 ms took 1001.450 ms: timeout
2019-01-21 08:04:51,710 - asyncio - INFO - poll 999.861 ms took 1003.482 ms: timeout
2019-01-21 08:04:52,724 - asyncio - INFO - poll 999.898 ms took 1000.244 ms: timeout

I'm not sure how this information is useful to the consumer of the asyncio module (perhaps I'm missing something) but to me, this looks like something that should be logged at the DEBUG level, not INFO.

Regardless, given that I was seeing these messages in my logfile, I found this to work quite well to get rid of them (source):

logging.getLogger('asyncio').setLevel(logging.WARNING)  # Remove asyncio debug and info messages, but leave warnings.

I added this to the startup file I have where all the app wide configuration is set before my process starts.

social