Skip to content

Commit 5fdbe71

Browse files
authored
Update examples.py
1 parent 5496ac2 commit 5fdbe71

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

logging-for-python-devs/examples.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,24 @@ def call_external_api(user_id):
111111

112112
fetch_user_data(123)
113113

114+
# from logger_config
115+
116+
from logger_config import setup_logger
117+
118+
logger = setup_logger(__name__)
119+
120+
def calculate_discount(price, discount_percent):
121+
logger.debug(f'Calculating discount: {price} * {discount_percent}%')
122+
123+
if discount_percent < 0 or discount_percent > 100:
124+
logger.warning(f'Invalid discount percentage: {discount_percent}')
125+
discount_percent = max(0, min(100, discount_percent))
126+
127+
discount = price * (discount_percent / 100)
128+
final_price = price - discount
129+
130+
logger.info(f'Applied {discount_percent}% discount: ${price} -> ${final_price}')
131+
return final_price
132+
133+
calculate_discount(100, 20)
134+
calculate_discount(100, 150)

0 commit comments

Comments
 (0)