So I've been trying to get logging to work with Django 1.9.5/Python 3 on a Waitress server running on Heroku, but I have been unable to so far. This is the configuration I have added to my production server Django settings:
settings.py
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"level": "INFO",
"class": "logging.StreamHandler",
"stream": sys.stdout
},
},
"loggers": {
"django": {
"handlers": ["console"],
}
}
}
views.py
logger = logging.getLogger(__name__)
class IndexView(View):
def get(self, request):
logger.info('This is a test INFO error')
return render(request, 'index.html', {})
Any ideas why this isn't outputting anything into my Heroku Papertrail?
Your logging configuration is set up to capture all logs under the django
namespace, but in your views.py
you are using a different namespace set with:
logger = logging.getLogger(__name__) # __name__ resolves to the name of your app.
You need to add your app (say it's called myapp
) to your logging config:
"loggers": {
"django": {
"handlers": ["console"],
},
"myapp": {
"handlers": ["console"],
}
}