0
0
No-Codeknowledge~10 mins

Error monitoring and logging in No-Code - Interactive Code Practice

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

Complete the code to start logging errors to a file named 'app.log'.

No-Code
logging.basicConfig(filename=[1], level=logging.ERROR)
Drag options to blanks, or click blank then click option'
A'debug.log'
B'error.log'
C'logfile.txt'
D'app.log'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong filename string.
Forgetting to put quotes around the filename.
2fill in blank
medium

Complete the code to log an error message 'File not found'.

No-Code
logging.[1]('File not found')
Drag options to blanks, or click blank then click option'
Ainfo
Berror
Cwarning
Ddebug
Attempts:
3 left
💡 Hint
Common Mistakes
Using logging.info() instead of logging.error().
Using logging.debug() which is for debugging, not errors.
3fill in blank
hard

Fix the error in the code to catch exceptions and log them.

No-Code
try:
    open('data.txt')
except Exception as [1]:
    logging.error('Failed to open file')
Drag options to blanks, or click blank then click option'
Ae
Bexception
Cex
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using reserved words like 'exception' as variable names.
Using names that are not valid identifiers.
4fill in blank
hard

Fill both blanks to log the exception message with traceback.

No-Code
except Exception as [1]:
    logging.error('Error occurred: %s', [2], exc_info=True)
Drag options to blanks, or click blank then click option'
Ae
Cerror
Dex
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the two blanks.
Not passing the exception variable to the logging call.
5fill in blank
hard

Fill both blanks to create a dictionary comprehension that logs only errors with code greater than 400.

No-Code
error_logs = [1]: [2] for } in logs.items() if {{BLANK_2} > 400
Drag options to blanks, or click blank then click option'
A{k
Bcode
C(k, code)
D}
Attempts:
3 left
💡 Hint
Common Mistakes
Not using curly braces to start the dictionary comprehension.
Using wrong variable names for keys or values.