0
0
HLDsystem_design~10 mins

Logging strategies in HLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the logging level to capture all messages.

HLD
logging.basicConfig(level=[1])
Drag options to blanks, or click blank then click option'
Alogging.DEBUG
B"ERROR"
C"WARNING"
D"CRITICAL"
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a higher level like ERROR filters out debug messages.
2fill in blank
medium

Complete the code to create a logger named 'appLogger'.

HLD
logger = logging.getLogger([1])
Drag options to blanks, or click blank then click option'
A"appLogger"
B"root"
C"main"
D"logger"
Attempts:
3 left
💡 Hint
Common Mistakes
Using default or unrelated logger names.
3fill in blank
hard

Fix the error in the code to add a file handler to the logger.

HLD
file_handler = logging.FileHandler([1])
logger.addHandler(file_handler)
Drag options to blanks, or click blank then click option'
Aapp_log.txt
B"app.log"
Capp.log
D"app_log.txt"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the filename causes a NameError.
4fill in blank
hard

Fill both blanks to format log messages with time and level.

HLD
formatter = logging.Formatter("[1] - [2] - %(message)s")
file_handler.setFormatter(formatter)
Drag options to blanks, or click blank then click option'
A%(asctime)s
B%(levelname)s
C%(message)s
D%(filename)s
Attempts:
3 left
💡 Hint
Common Mistakes
Using message or filename instead of time or level in the blanks.
5fill in blank
hard

Fill all three blanks to create a dictionary that filters logs with level ERROR or higher.

HLD
error_logs = {k: v for k, v in logs.items() if v['level'] [1] [2] and v['level'] [3] 'CRITICAL'}
Drag options to blanks, or click blank then click option'
A>=
B'ERROR'
C<=
D'WARNING'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong operators or levels causing wrong filtering.