Please consider this dummy code.
$ cat dummy.py
import logging
import time
from boto3.session import Session
# Logging Configuration
fmt = '%(asctime)s [%(levelname)s] [%(module)s] - %(message)s'
logging.basicConfig(level='INFO', format=fmt, datefmt='%m/%d/%Y %I:%M:%S')
logger = logging.getLogger()
def main():
session = Session(region_name='us-west-2')
client = session.client('ec2')
response = client.describe_instances(InstanceIds=['i-11111111111111111'])
logger.info('The instnace size is: %s', response[
'Reservations'][0]['Instances'][0]['InstanceType'])
if __name__ == '__main__':
main()
Output:
$ python3 dummy.py
03/03/2017 08:47:00 [INFO] [credentials] - Found credentials in shared credentials file: ~/.aws/credentials
03/03/2017 08:47:01 [INFO] [connectionpool] - Starting new HTTPS connection (1): ec2.us-west-2.amazonaws.com
03/03/2017 08:47:02 [INFO] [dummy] - The instnace size is: t2.micro
Question: How to avoid below lines from being printed?
03/03/2017 08:47:00 [INFO] [credentials] - Found credentials in shared credentials file: ~/.aws/credentials
03/03/2017 08:47:01 [INFO] [connectionpool] - Starting new HTTPS connection (1): ec2.us-west-2.amazonaws.com
If I change logging.basicConfig(level='INFO',...
to logging.basicConfig(level='WARNING',...
then Those messages are not printed, but then all my messages get logged with WARNING
severity.
I just want the logging
module to print the messages that I explicitly write using logger.info ....
and nothing else. Hence I need any pointers on how to avoid the unnecessary messages from being printed.