djangopython-2.7tornadouwsgidjango-logging

Django application not logging tornado daemon uwsgi


I am trying to log my django application. This works fine (I see all other logs in the logfile) unless I try to log my uWSGI daemonized processes. I am new to using a daemon, is there a reason why it would log differently?

I am using in uwsgi.yaml:

env: DJANGO_SETTINGS_MODULE=application.settings
module: application.wsgi
log-master: True
log-syslog: uwsgi
attach-daemon: /opt/application/bin/tornading

This is my Logging in the settings module:

LOGGING = {
    'handlers': {
        'logfile': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': '/var/log/application.log',
            'maxBytes': 1 * 1024 * 1024,
            'backupCount': 2,
            'formatter': 'standard',
        },
    },
    'loggers': {
        'application': {
            'handlers': ['logfile'],
            'level': 'DEBUG',
            'propagate': True,
        },
    }
}

tornading.py starts an IOloop instance and a tornado consumer:

import logging
import settings
LOGGER = logging.getLogger(__name__)

def main():
    app = tornado.web.Application(BroadcastRouter.urls)
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(port=settings.TORNADO_PORT, address=settings.TORNADO_HOST)
    ioloop = tornado.ioloop.IOLoop.instance()
    consumer = communication.TornadoConsumer(ioloop, BroadcastConnection.on_rabbit_message)
    consumer.connect()

    LOGGER.debug('Hello world')

    ioloop.start()

if __name__ == "__main__":
    main()

I have also tried LOGGER = logging.getLogger('application') and still no logging from tornading.py

Any ideas on why this is not working?


Solution

  • When you use Django - you don't need configure logger, because Django make it themselves when load.

    When you use Tornado there is no autoconfig loggger. Try to config manually.

    import logging.config
    
    logging.config.dictConfig(settings.LOGGING)
    

    Also for future reading: 15.8. logging.config — Logging configuration