I have created an app on Heroku and I push my Django app to it.
I monitor the logs using heroku logs --tail
to see them in real time.
Then, in my settings.py
, I have the following:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': ('%(asctime)s [%(process)d] [%(levelname)s] ' +
'pathname=%(pathname)s lineno=%(lineno)s ' +
'funcname=%(funcName)s %(message)s'),
'datefmt': '%Y-%m-%d %H:%M:%S'
},
'simple': {
'format': '%(levelname)s %(message)s'
}
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
},
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
'stream': sys.stdout,
}
},
'loggers': {
'MYAPP': {
'handlers': ['console'],
'level': 'INFO',
}
}
}
Then, when I want to log something, I use the following:
import logging
import sys
logger = logging.getLogger('MYAPP')
logger.info('My message here...')
sys.stdout.flush()
but it isn't reflected in my logs.
My Procfile
:
web: gunicorn myapp.wsgi --log-file=-
EDIT: Curiously, I can actually change "myapp" to "django" when I define my logging config and also logging.getLogger('django')
and that allows me to see anything using print
in my logs, but nothing from the formatted logger I've defined.
I even have PYTHONUNBUFFERED=true
and DEBUG=1
set for my staging environment, but I don't see any of the logs that I see when using my local version with foreman start web
.
What is causing this and how do I see my logs live in Heroku?
Procfile
is:web: gunicorn myapp.wsgi --log-file -
– Refusallevel
option ofconsole
toDEBUG
? – Excrescency