Disable boto logging without modifying the boto files

后端 未结 6 494
野趣味
野趣味 2020-12-23 17:20

I am using the Boto library to talk to AWS. I want to disable logging. (Or redirect to /dev/null or other file). I cant find an obvious way to do this. I tried this, but tha

6条回答
  •  无人及你
    2020-12-23 18:08

    I move the boto3 answer from the comments (namely charneykaye and gene_wood) to a proper answer:

    import logging
    
    logger = logging.getLogger()
    logger.addHandler(logging.StreamHandler()) # Writes to console
    logger.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 boto3
    
    s3 = boto3.resource('s3')
    
    for bucket in s3.buckets.all():
        print(bucket.name)
    

    To get all the loggers follow the response from leobarcellos:

    import logging
    loggers_dict = logging.Logger.manager.loggerDict
    

提交回复
热议问题