Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda