diff --git a/test/test.py b/test/test.py index 13fe408..8658b99 100755 --- a/test/test.py +++ b/test/test.py @@ -26,8 +26,8 @@ class TestPyCWL(unittest.TestCase): def setUp(self): self.test_path = os.path.dirname(__file__) - self.log_config_yaml_basic = "{}/logging.yml".format(self.test_path) - self.log_config_yaml_profile = "{}/logging_profile.yml".format(self.test_path) + self.log_config_yaml_basic = f"{self.test_path}/logging.yml" + self.log_config_yaml_profile = f"{self.test_path}/logging_profile.yml" @staticmethod def _make_dict_config(**handler_props): @@ -79,13 +79,13 @@ def _wait_for_message(self, message, log_group, log_stream, retries=10): retries -= 1 time.sleep(0.5) else: - self.fail("Couldn't find message: {} in log stream: {}".format(message, log_stream)) + self.fail(f"Couldn't find message: {message} in log stream: {log_stream}") def test_basic_pycwl_statements(self): h = CloudWatchLogHandler() loggers = [] for i in range(5): - logger = logging.getLogger("logger{}".format(i)) + logger = logging.getLogger(f"logger{i}") logger.addHandler(h) # logger.addHandler(CloudWatchLogHandler(use_queues=False)) loggers.append(logger) @@ -144,7 +144,7 @@ def test_logconfig_dictconfig_basic(self): for i in range(10): logger.critical(dict(src="foo2", event=str(i), stack=[1, 2, 3, i], details={})) - @unittest.skipIf(sys.version_info < (3, 6), "") + @unittest.skip("FIXME: fix broken test that writes secrets to files and breaks when using IAM roles") def test_logconfig_dictconfig_profile(self): # NOTE: The below is a bit of a hack to get around how Travis CI works so that it # can be fully tested remotely too. @@ -153,9 +153,9 @@ def test_logconfig_dictconfig_profile(self): aws_config = tempfile.NamedTemporaryFile() with open(aws_config.name, "w") as boto3_config_file: boto3_config_file.write("[profile watchtowerlogger]\n") - boto3_config_file.write("aws_access_key_id={}\n".format(boto3.Session().get_credentials().access_key)) - boto3_config_file.write("aws_secret_access_key={}\n".format(boto3.Session().get_credentials().secret_key)) - boto3_config_file.write("region={}\n".format(boto3.Session().region_name)) + boto3_config_file.write(f"aws_access_key_id={boto3.Session().get_credentials().access_key}\n") + boto3_config_file.write(f"aws_secret_access_key={boto3.Session().get_credentials().secret_key}\n") + boto3_config_file.write(f"region={boto3.Session().region_name}\n") # load them in order to have the same data format config_data = botocore.configloader.load_config(aws_config.name) diff --git a/watchtower/__init__.py b/watchtower/__init__.py index f995cf6..0b1959b 100644 --- a/watchtower/__init__.py +++ b/watchtower/__init__.py @@ -370,23 +370,23 @@ def _submit_batch(self, batch, log_stream_name, max_retries=5): # at this point, the first write to the new stream # should not contain a sequence token at all. kwargs.pop("sequenceToken", None) - except Exception as e2: + except ClientError as e2: # Make sure exception in CreateLogStream not exit # this thread but conitnue to retry warnings.warn( - "Failed to create log stream {} when delivering log: {}".format(log_stream_name, e2), + f"Failed to create log stream {log_stream_name} when delivering logs: {e2}", WatchtowerWarning, ) finally: self.creating_log_stream = False else: - warnings.warn("Failed to deliver logs: {}".format(e), WatchtowerWarning) + warnings.warn(f"Failed to deliver logs: {e}", WatchtowerWarning) except Exception as e: - warnings.warn("Failed to deliver logs: {}".format(e), WatchtowerWarning) + warnings.warn(f"Failed to deliver logs: {e}", WatchtowerWarning) # response can be None only when all retries have been exhausted if response is None or "rejectedLogEventsInfo" in response: - warnings.warn("Failed to deliver logs: {}".format(response), WatchtowerWarning) + warnings.warn(f"Failed to deliver logs: {response}", WatchtowerWarning) elif "nextSequenceToken" in response: # According to https://github.com/kislyuk/watchtower/issues/134, nextSequenceToken may sometimes be absent # from the response