Disable boto logging without modifying the boto files
You could try
import logginglogging.getLogger('boto').setLevel(logging.CRITICAL)
which will suppress all (other than CRITICAL) errors.
Boto uses logging configuration files (e.g. /etc/boto.cfg
, ~/.boto
) so see if you can configure it to your needs that way.
The set_file_logger
call simply adds a user-defined file to the logging setup, so you can't use that to turn logging off.
I move the boto3 answer from the comments (namely charneykaye and gene_wood) to a proper answer:
import logginglogger = logging.getLogger()logger.addHandler(logging.StreamHandler()) # Writes to consolelogger.setLevel(logging.DEBUG)logging.getLogger('boto3').setLevel(logging.CRITICAL)logging.getLogger('botocore').setLevel(logging.CRITICAL)logging.getLogger('s3transfer').setLevel(logging.CRITICAL)logging.getLogger('urllib3').setLevel(logging.CRITICAL)import boto3s3 = boto3.resource('s3')for bucket in s3.buckets.all(): print(bucket.name)
To get all the loggers follow the response from leobarcellos:
import loggingloggers_dict = logging.Logger.manager.loggerDict
Better yet, disable propagate
for boto:
import botoboto.set_file_logger('boto', 'logs/boto.log')logging.getLogger('boto').propagate = False