Complete the code to import the Django logging module.
import [1]
The logging module is used in Django for monitoring and error tracking by capturing logs.
Complete the code to configure a logger named 'django' in Django settings.
""" LOGGING = { 'loggers': { 'django': { 'handlers': ['console'], 'level': '[1]', }, }, } """
The DEBUG level captures detailed information useful for diagnosing problems during development.
Fix the error in the code to send error logs to Sentry in Django.
import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration sentry_sdk.init( dsn=[1], integrations=[DjangoIntegration()], traces_sample_rate=1.0, send_default_pii=True )
The DSN must be a string, so it needs quotes around it.
Fill both blanks to create a custom logging filter that only allows ERROR level logs.
class ErrorFilter(logging.Filter): def filter(self, record): return record.levelno [1] logging.ERROR LOGGING = { 'filters': { 'error_only': { '()': ErrorFilter, }, }, 'handlers': { 'error_console': { 'class': 'logging.StreamHandler', 'filters': ['[2]'], }, }, }
The filter method should check if the log level equals ERROR using ==. The handler uses the filter named error_only.
Fill both blanks to define a dictionary comprehension that maps each app name to its error count if count is greater than zero.
error_counts = {app:count for app, count in app_errors.items() if count [1] 0}
filtered_errors = {k: v for k, v in error_counts.items() if v [2] 0}The dictionary comprehension uses ':' to map keys to values. The condition count > 0 filters positive counts. The second filter keeps items where value is not zero using !=.