14

I'm not seeing log entries (at a level of INFO) made by Django in my Heroku logs.

This is my configuration:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse',
        },
        'require_debug_true': {
            '()': 'django.utils.log.RequireDebugTrue',
        },
        'not_development_filter': {
            '()': NotDevelopmentFilter,
        },
    },
    'handlers': {
        'console':{
            'level': 'INFO',
            'class': 'logging.StreamHandler',
        },
        'null': {
            'class': 'django.utils.log.NullHandler',
        },
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['not_development_filter'],
            'class': 'django.utils.log.AdminEmailHandler',
            'include_html': True,
        }
    },
    'loggers': {
        '': {
            'handlers': ['mail_admins', 'console'],
            'level': 'INFO',
        },
        'django': {
            'handlers': ['console'],
        },
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': False,
        },
        'py.warnings': {
            'handlers': ['console'],
        },
    }
}

I'd like to see the log entries in the Heroku interface. Any idea why I'm not seeing them there?

  • Do you see anything if you just print something to stdout? – anatoly techtonik Oct 9 '16 at 5:42
  • It's been two years ;) – Ram Rachum Oct 10 '16 at 11:29
  • 3
    I found it is still unanswered. =) – anatoly techtonik Oct 10 '16 at 20:56
  • 1
    @RamRachum If it's solved, write an answer, or close it somehow - otherwise it'll continue to pop up on people's radar. – Mike Fiedler Dec 22 '17 at 14:15
1

In the python-getting-started app, for a log that isn't tagged django, ERROR level logs show up in heroku logs, but INFO logs don't.

To make it work for logs that aren't tagged django, it needs a config like the following (similar to yours):

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        '': {
            'handlers': ['console'],
            'level': 'INFO',
        },
        'django': {
            'handlers': ['console'],
            'level': 'INFO',
        },
    },
}

So if you adjust your configuration to otherwise be like python-getting-started, including the Procfile, it should hopefully work.

Here's a log that isn't tagged django, that I added to views/hello.py:

import logging
logger = logging.getLogger(__name__)

# Create your views here.
def index(request):
    logger.error('testing logging!')
    logger.info('testing info logging')
    logger.debug('testing debug logging')

    # return HttpResponse('Hello from Python!')
    return render(request, 'index.html')

When I first tried it, only the error log showed up. When I added the logging config in the code snippet above the previous one, the info and the error logs showed up. This is all with DEBUG = False (changed from the code in the repo, which has DEBUG = True).

It probably is better to, rather than have the empty string key, so everything is logged, to have a more specific loggers entries than just the empty string ('').

Finally, in your log file, there's a case where INFO logs won't appear on the console, or Heroku logs: If it's an INFO log to django.request, with your config it will only go to 'mail_admins' because propagate is False. I think that in this case, it would make more sense for propagate to be set to True.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.