Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the logging module.
Selenium Python
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like sys or os.
Forgetting to import the logging module.
✗ Incorrect
The logging module is used to set up logging in Python.
2fill in blank
mediumComplete the code to set the logging level to DEBUG.
Selenium Python
logging.basicConfig(level=[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using INFO or WARNING which show fewer messages.
Using ERROR which only shows errors.
✗ Incorrect
Setting level=logging.DEBUG enables detailed debug messages.
3fill in blank
hardFix the error in the code to log an info message.
Selenium Python
logging.[1]("Test started")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'warn' which is deprecated; should use 'warning'.
Using a non-existent method like 'loginfo'.
✗ Incorrect
The correct method to log an info message is info.
4fill in blank
hardFill both blanks to create a logger and set its level to WARNING.
Selenium Python
logger = logging.getLogger([1]) logger.setLevel([2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using DEBUG level when WARNING is required.
Using root logger name when a custom name is better.
✗ Incorrect
Create a named logger with getLogger and set its level to WARNING to filter messages.
5fill in blank
hardFill all three blanks to add a file handler that writes logs to 'app.log' with ERROR level.
Selenium Python
file_handler = logging.FileHandler([1]) file_handler.setLevel([2]) logger.addHandler([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong filename string.
Setting the wrong logging level.
Forgetting to add the handler to the logger.
✗ Incorrect
The file handler writes logs to 'app.log' and filters messages at ERROR level. It is then added to the logger.