-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathlogs_3.py
More file actions
executable file
·41 lines (34 loc) · 1.4 KB
/
logs_3.py
File metadata and controls
executable file
·41 lines (34 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import logging
import logging.config
# Configure basic logging with a slightly more informative format
logging.config.fileConfig('logging.conf')
def check_temperature(temperature):
"""Checks the temperature and logs a message based on its value."""
logging.info(f"Checking temperature: {temperature}°C")
if temperature > 30:
logging.warning(f"Temperature is high: {temperature}°C. Consider taking precautions.")
elif temperature < 10:
logging.warning(f"Temperature is low: {temperature}°C. Dress warmly.")
else:
logging.info(f"Temperature is comfortable: {temperature}°C.")
def calculate_area(length, width):
"""Calculates the area of a rectangle and logs the dimensions."""
logging.debug(f"Calculating area for length={length}, width={width}")
if length < 0 or width < 0:
logging.error("Invalid dimensions! Length and width must be non-negative.")
return None
area = length * width
logging.info(f"Area of rectangle: {area}")
return area
def main():
"""Main function demonstrating temperature check and area calculation."""
logging.info(f"starting python logging code")
check_temperature(35)
check_temperature(5)
check_temperature(20)
area1 = calculate_area(5, 10)
logging.info(f"Area 1: {area1}")
area2 = calculate_area(-2, 8)
logging.info(f"Area 2: {area2}")
if __name__ == "__main__":
main()