6

I'm trying to debug a django app of mine, but it's hard because I have no idea where my print statements are sending their output. I'm using flup and fastcgi with django and nginx, and I can see python errors and access logs via nginx, but I have no idea where my print statements are going.

Here's the relevant stuff from my nginx.conf file:

server {
    listen 80;
    server_name localhost;
    access_log /var/log/nginx/demo.access.log;
    error_log /var/log/nginx/demo.error.log;

    location / {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9001;
    }
}

And i'm running fastcgi using this command:

python manage.py runfcgi host=127.0.0.1 port=9001

I basically followed this tutorial https://code.djangoproject.com/wiki/DjangoAndNginx and my OS is ubuntu!

Thanks for the help!

jmetz
  • 815
  • 1
  • 9
  • 19
  • 2
    You might be better off just setting up some basic logging with a file handler. Take a look at the logging how to at http://docs.python.org/2/howto/logging.html. It's not much trouble to set up and you can just turn logging off rather than constantly go through your code and add and delete print statements. – BenTrofatter Nov 17 '12 at 04:29
  • Yep, logging is your friend. – Hamish Nov 17 '12 at 05:30
  • Not really related to question but I think the general understanding is that fastcgi is not the best method for deploying web apps on nginx. Fastcgi works great for Apache but on nginx, the better way is to use `proxy_pass` and then use something like gevent or gunicord so serve your django app. – miki725 Nov 17 '12 at 06:03
  • This is just a local testing environment, and I'm really not too keen on figuring out how to set up everything all over again. Thanks for your comment though, I appreciate it. – jmetz Nov 17 '12 at 07:28
  • 1
    @miki725 FastCGI works great for nginx too. – VBart Nov 17 '12 at 13:36
  • 1
    Your print output goes to flup's terminal. If it doesn't have one (i.e. run as daemon in background), then it probably goes to /dev/null. – VBart Nov 17 '12 at 13:38

1 Answers1

2

I agree with the logging recommendation, but these days the link should point to the integrated Django functionality, not just to the base Python libs.

https://docs.djangoproject.com/en/dev/topics/logging/

With a basic setup and something simple like the following at the top of your Python code:

import logging
log = logging.getLogger(__name__)

You can then do stuff like this in your code:

log.debug('output message')

which will land where you Django logging settings are pointed.

slumtrimpet
  • 3,159
  • 2
  • 31
  • 44