Skip to content

Commit

Permalink
Revert the log f-string change
Browse files Browse the repository at this point in the history
  • Loading branch information
aahung committed Aug 12, 2023
1 parent 0f197b5 commit a7c5e3b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ ignore = [
# Mutable class attributes should be annotated with `typing.ClassVar`
# Too many violations
"RUF012",
# Logging statement uses f-string
"G004",
]

# Mininal python version we support is 3.7
Expand Down
12 changes: 6 additions & 6 deletions samtranslator/feature_toggle/feature_toggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _get_dialup(self, region_config, feature_name): # type: ignore[no-untyped-d
return FeatureToggle.DIALUP_RESOLVER[dialup_type](
region_config, account_id=self.account_id, feature_name=feature_name
)
LOG.warning("Dialup type '%s' is None or is not supported.", dialup_type)
LOG.warning(f"Dialup type '{dialup_type}' is None or is not supported.")
return DisabledDialup(region_config)

def is_enabled(self, feature_name: str) -> bool:
Expand All @@ -66,21 +66,21 @@ def is_enabled(self, feature_name: str) -> bool:
:param feature_name: name of feature
"""
if feature_name not in self.feature_config:
LOG.warning("Feature '%s' not available in Feature Toggle Config.", feature_name)
LOG.warning(f"Feature '{feature_name}' not available in Feature Toggle Config.")
return False

stage = self.stage
region = self.region
account_id = self.account_id
if not stage or not region or not account_id:
LOG.warning(
"One or more of stage, region and account_id is not set. Feature '%s' not enabled.", feature_name
f"One or more of stage, region and account_id is not set. Feature '{feature_name}' not enabled."
)
return False

stage_config = self.feature_config.get(feature_name, {}).get(stage, {})
if not stage_config:
LOG.info("Stage '%s' not enabled for Feature '%s'.", stage, feature_name)
LOG.info(f"Stage '{stage}' not enabled for Feature '{feature_name}'.")
return False

if account_id in stage_config:
Expand All @@ -90,10 +90,10 @@ def is_enabled(self, feature_name: str) -> bool:
region_config = stage_config[region] if region in stage_config else stage_config.get("default", {})

dialup = self._get_dialup(region_config, feature_name=feature_name) # type: ignore[no-untyped-call]
LOG.info("Using Dialip %s", dialup)
LOG.info(f"Using Dialip {dialup}")
is_enabled: bool = dialup.is_enabled()

LOG.info("Feature '%s' is enabled: '%r'", feature_name, is_enabled)
LOG.info(f"Feature '{feature_name}' is enabled: '{is_enabled}'")
return is_enabled


Expand Down
4 changes: 2 additions & 2 deletions samtranslator/metrics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _flush_metrics(self, namespace, metrics): # type: ignore[no-untyped-def]
if metric_data:
self.cloudwatch_client.put_metric_data(Namespace=namespace, MetricData=metric_data)
except Exception:
LOG.exception("Failed to report %d metrics", len(metric_data))
LOG.exception(f"Failed to report {len(metric_data)} metrics")


class DummyMetricsPublisher(MetricsPublisher):
Expand All @@ -73,7 +73,7 @@ def __init__(self) -> None:

def publish(self, namespace: str, metrics: List["MetricDatum"]) -> None:
"""Do not publish any metric, this is a dummy publisher used for offline use."""
LOG.debug("Dummy publisher ignoring %d metrices", len(metrics))
LOG.debug(f"Dummy publisher ignoring {len(metrics)} metrices")


class Unit:
Expand Down
10 changes: 5 additions & 5 deletions samtranslator/plugins/application/serverless_app_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ def _handle_get_application_request(self, app_id, semver, key, logical_id): # t
:param string key: The dictionary key consisting of (ApplicationId, SemanticVersion)
:param string logical_id: the logical_id of this application resource
"""
LOG.info("Getting application %s/%s from serverless application repo...", app_id, semver)
LOG.info(f"Getting application {app_id}/{semver} from serverless application repo...")
try:
self._sar_service_call(self._get_application, logical_id, app_id, semver)
self._applications[key] = {"Available"}
LOG.info("Finished getting application %s/%s.", app_id, semver)
LOG.info(f"Finished getting application {app_id}/{semver}.")
except EndpointConnectionError as e:
# No internet connection. Don't break verification, but do show a warning.
warning_message = f"{e}. Unable to verify access to {app_id}/{semver}."
Expand All @@ -238,10 +238,10 @@ def _handle_create_cfn_template_request(self, app_id, semver, key, logical_id):
:param string key: The dictionary key consisting of (ApplicationId, SemanticVersion)
:param string logical_id: the logical_id of this application resource
"""
LOG.info("Requesting to create CFN template %s/%s in serverless application repo...", app_id, semver)
LOG.info(f"Requesting to create CFN template {app_id}/{semver} in serverless application repo...")
response = self._sar_service_call(self._create_cfn_template, logical_id, app_id, semver)

LOG.info("Requested to create CFN template %s/%s in serverless application repo.", app_id, semver)
LOG.info(f"Requested to create CFN template {app_id}/{semver} in serverless application repo.")
self._applications[key] = response[self.TEMPLATE_URL_KEY]
if response["Status"] != "ACTIVE":
self._in_progress_templates.append((response[self.APPLICATION_ID_KEY], response["TemplateId"]))
Expand Down Expand Up @@ -360,7 +360,7 @@ def on_after_transform_template(self, template): # type: ignore[no-untyped-def]
except ClientError as e:
error_code = e.response["Error"]["Code"]
if error_code == "TooManyRequestsException":
LOG.debug("SAR call timed out for application id %s", application_id)
LOG.debug(f"SAR call timed out for application id {application_id}")
break # We were throttled by SAR, break out to a sleep
raise e

Expand Down

0 comments on commit a7c5e3b

Please sign in to comment.