Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
Understanding django's logging

I am a bit confused on how django is handling the logging. I have this setting for loggers in my settings:

Logging settings

LOGGING = {
    ...
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
        },
        'file': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': LOG_BASE_DIRECTORY + '/django.log',
            'maxBytes': LOGFILE_SIZE,
            'backupCount': LOGFILE_COUNT,
            'formatter': 'verbose'
        },
        'mail_admins': {
             'level': 'ERROR',
             #'filters': ['require_debug_false'],
             'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django': {
            'handlers': ['file','mail_admins'],
            'level': 'INFO',
            'propagate': True,
        },
        'app1': {
            'handlers': ['file','mail_admins'],
            'level': 'DEBUG',
            'propagate': True,
        },

        ...
    },
}

As one can see, I have 2 handlers defined for django and app logs, file and mail_admins. The log level for file is debug. Hence I assume all logs which are debug and above shall use this handler. The level for mail_admins is error. The problem that I am seeing though is that in case of 500 errors while email handler runs and sends the mail there is no logging on the file.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

For logging errors you need to log them in your code. Something like this

import logging

try:
    # your code here
except Exception as e:
    logging.getLogger("logger_name").error(repr(e))

refer this official doc link for same or this article for video and working github code.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda