A. logging.debug() cannot be called before configuring logging
B. The level argument should be an integer, not a string
C. logging.basicConfig() requires a filename argument
D. There is no error; the code runs correctly
Solution
Step 1: Check logging.basicConfig level argument type
The level argument must be a logging level constant like logging.DEBUG, not a string.
Step 2: Validate other options
logging.debug() can be called after basicConfig; filename is optional; code errors due to string level.
Final Answer:
The level argument should be an integer, not a string -> Option B
Quick Check:
Level must be logging.DEBUG, not 'DEBUG' string [OK]
Hint: Use logging.DEBUG constant, not 'DEBUG' string for level [OK]
Common Mistakes:
Passing level as string instead of logging constant
Thinking filename is mandatory in basicConfig
Calling logging.debug before configuration causes error
5. You want to log Selenium test events to a file named test.log with timestamps and message levels. Which code snippet correctly sets this up?
hard
A. logging.basicConfig(filename='test.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
B. logging.basicConfig(file='test.log', level='INFO', format='%(time)s - %(level)s - %(msg)s')
C. logging.setup(filename='test.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
D. logging.basicConfig(filename='test.log', level=logging.DEBUG, format='%(message)s')
Solution
Step 1: Identify correct parameters for file logging
Use filename='test.log', level=logging.INFO, and correct format string with asctime and levelname.
Step 2: Check each option for correctness
logging.basicConfig(filename='test.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') uses correct parameter names and format; A uses wrong keys and strings; C uses non-existent logging.setup; D misses timestamps and uses DEBUG level.
Final Answer:
logging.basicConfig(filename='test.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') -> Option A