In Python, which statement inside an exception handler logs an error message?

Get ready for your WGU ITEC2034 D385 Software Security and Testing Test. Study with multiple choice questions that include hints and explanations. Boost your confidence for your exam day!

Multiple Choice

In Python, which statement inside an exception handler logs an error message?

Explanation:
Logging errors in Python is handled with the logging module, and inside an exception handler you want to record a message at the error level so it’s treated as an actual error condition in your logs. The statement that uses the logging module to log at the error level fits this need, because it integrates with your configured handlers (console, file, etc.) and includes the appropriate severity. Printing to the console bypasses the logging framework and won’t respect levels or destinations. Writing to a file with write() operates outside the logging system and misses consistent formatting and metadata. Logging at an informational level would not properly indicate an error. If you need the full traceback, you can use a variant like logging.exception inside the except block, which logs the error and the stack trace at the error level.

Logging errors in Python is handled with the logging module, and inside an exception handler you want to record a message at the error level so it’s treated as an actual error condition in your logs. The statement that uses the logging module to log at the error level fits this need, because it integrates with your configured handlers (console, file, etc.) and includes the appropriate severity. Printing to the console bypasses the logging framework and won’t respect levels or destinations. Writing to a file with write() operates outside the logging system and misses consistent formatting and metadata. Logging at an informational level would not properly indicate an error. If you need the full traceback, you can use a variant like logging.exception inside the except block, which logs the error and the stack trace at the error level.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy