Skip to content

Commit 881393b

Browse files
committed
formatting
1 parent 6f64cd4 commit 881393b

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

python/aws_lambda_powertools/logging/logger.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
def logger_setup(
19-
service: str = "service_undefined", level: str = "INFO", sampling_rate: float = 0.0, **kwargs
19+
service: str = "service_undefined", level: str = "INFO", sampling_rate: float = 0.0, **kwargs
2020
):
2121
"""Setups root logger to format statements in JSON.
2222
@@ -29,7 +29,7 @@ def logger_setup(
2929
service name
3030
LOG_LEVEL: str
3131
logging level (e.g. INFO, DEBUG)
32-
POWERTOOLS_SAMPLE_RATE: str
32+
POWERTOOLS_LOGGER_SAMPLE_RATE: str
3333
samping rate ranging from 0 to 1, float precision
3434
3535
Parameters
@@ -65,7 +65,7 @@ def logger_setup(
6565
6666
"""
6767
service = os.getenv("POWERTOOLS_SERVICE_NAME") or service
68-
sampling_rate = os.getenv("POWERTOOLS_SAMPLE_RATE") or sampling_rate
68+
sampling_rate = os.getenv("POWERTOOLS_LOGGER_SAMPLE_RATE") or sampling_rate
6969
log_level = os.getenv("LOG_LEVEL") or level
7070
logger = logging.getLogger(name=service)
7171

@@ -75,7 +75,9 @@ def logger_setup(
7575
if sampling_rate and random.random() <= float(sampling_rate):
7676
log_level = logging.DEBUG
7777
except ValueError:
78-
logger.debug("POWERTOOLS_SAMPLE_RATE provided value {0} is not valid.".format(sampling_rate))
78+
logger.debug(
79+
"POWERTOOLS_LOGGER_SAMPLE_RATE provided value {0} is not valid.".format(sampling_rate)
80+
)
7981

8082
logger.setLevel(log_level)
8183

@@ -88,7 +90,7 @@ def logger_setup(
8890

8991

9092
def logger_inject_lambda_context(
91-
lambda_handler: Callable[[Dict, Any], Any] = None, log_event: bool = False
93+
lambda_handler: Callable[[Dict, Any], Any] = None, log_event: bool = False
9294
):
9395
"""Decorator to capture Lambda contextual info and inject into struct logging
9496
@@ -183,12 +185,12 @@ def __is_cold_start() -> str:
183185

184186

185187
def log_metric(
186-
name: str,
187-
namespace: str,
188-
unit: MetricUnit,
189-
value: float = 0,
190-
service: str = "service_undefined",
191-
**dimensions,
188+
name: str,
189+
namespace: str,
190+
unit: MetricUnit,
191+
value: float = 0,
192+
service: str = "service_undefined",
193+
**dimensions,
192194
):
193195
"""Logs a custom metric in a statsD-esque format to stdout.
194196

python/tests/functional/test_aws_lambda_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,4 @@ class X:
112112

113113
log_dict = json.loads(stdout.getvalue())
114114

115-
assert log_dict["message"]["x"].startswith("<")
115+
assert log_dict["message"]["x"].startswith("<")

python/tests/functional/test_logger.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ def test_setup_service_env_var(monkeypatch, root_logger, stdout):
8181

8282

8383
def test_setup_sampling_rate(monkeypatch, root_logger, stdout):
84-
# GIVEN samping rate is explicitly defined via POWERTOOLS_SAMPLE_RATE env
84+
# GIVEN samping rate is explicitly defined via POWERTOOLS_LOGGER_SAMPLE_RATE env
8585
# WHEN logger is setup
86-
# THEN sampling rate should be equals POWERTOOLS_SAMPLE_RATE value
86+
# THEN sampling rate should be equals POWERTOOLS_LOGGER_SAMPLE_RATE value
8787
sampling_rate = "0.1"
88-
monkeypatch.setenv("POWERTOOLS_SAMPLE_RATE", sampling_rate)
88+
monkeypatch.setenv("POWERTOOLS_LOGGER_SAMPLE_RATE", sampling_rate)
8989

9090
logger = logger_setup()
9191
logger.info("Hello")
@@ -141,7 +141,7 @@ def handler(event, context):
141141

142142

143143
def test_inject_lambda_context_log_event_request_env_var(
144-
monkeypatch, root_logger, stdout, lambda_context
144+
monkeypatch, root_logger, stdout, lambda_context
145145
):
146146
# GIVEN a lambda function is decorated with logger instructed to log event
147147
# via POWERTOOLS_LOGGER_LOG_EVENT env
@@ -172,7 +172,7 @@ def handler(event, context):
172172

173173

174174
def test_inject_lambda_context_log_no_request_by_default(
175-
monkeypatch, root_logger, stdout, lambda_context
175+
monkeypatch, root_logger, stdout, lambda_context
176176
):
177177
# GIVEN a lambda function is decorated with logger
178178
# WHEN logger is setup
@@ -293,12 +293,12 @@ def test_log_metric_multiple_dimensions(capsys):
293293
"invalid_input,expected",
294294
[
295295
(
296-
{"unit": "seconds"},
297-
"MONITORING|0|Seconds|test_metric|DemoApp|service=service_undefined\n",
296+
{"unit": "seconds"},
297+
"MONITORING|0|Seconds|test_metric|DemoApp|service=service_undefined\n",
298298
),
299299
(
300-
{"unit": "Seconds", "customer": None, "charge_id": "123", "payment_status": ""},
301-
"MONITORING|0|Seconds|test_metric|DemoApp|service=service_undefined,charge_id=123\n",
300+
{"unit": "Seconds", "customer": None, "charge_id": "123", "payment_status": ""},
301+
"MONITORING|0|Seconds|test_metric|DemoApp|service=service_undefined,charge_id=123\n",
302302
),
303303
],
304304
ids=["metric unit as string lower case", "empty dimension value"],

0 commit comments

Comments
 (0)