PCPP 32 10x PCPP Certified Professional Python Programmer 1 · Free Practice Question Easy
Question 42
Which of the following logs represents the default formatting of the root logger (logging module)?
-
A
CRITICAL:root:Message -
B
Message:CRITICAL:root -
C
root:Message:CRITICAL -
D
CRITICAL:Message:root
Reveal correct answer
Correct answer: A
A.
This matches the default log format of the root logger, where CRITICAL is the log level, root is the name of the logger, and Message is the log message.
Example:
- import logging
- logging.basicConfig()
- logger = logging.getLogger()
- logger.critical('Your CRITICAL message')
- logger.error('Your ERROR message')
- logger.warning('Your WARNING message')
- logger.info('Your INFO message')
- logger.debug('Your DEBUG message')
Output:
- CRITICAL:root:Your CRITICAL message
- ERROR:root:Your ERROR message
- WARNING:root:Your WARNING message
B.
This format is incorrect because it places the message first, followed by the log level and logger name, which is not how the default logging format is structured.
C.
This format incorrectly positions the logger name before the message and the log level.
D.
This format places the log level first, followed by the message and logger name, which does not match the default formatting.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
