WebFaction
Community site: login faq

If I use "print" (or "pprint") in a django view:

def xfer(request):
    if request.method == 'POST':
        xfer= request.POST.get("xfer","")
        xfer2 = demjson.decode(xfer, strict=False)
        pprint(xfer2)

Where do the logs go? I was expecting to find them in ~/logs/user/error_XXXX.log

asked 30 Nov '11, 11:05

brycenesbitt
92919
accept rate: 0%


Mod_wsgi 'eats' prints and anything going to sys.stdout. You have to print to sys.stderr.

import sys
print >> sys.stderr, 'foo'

That will put it in the error logs in ~/logs/, you can grep for 'error' to find them.

permanent link

answered 01 Dec '11, 01:31

johns
5.4k312
accept rate: 23%

Alternatively, you can put this in your WSGI script:

sys.stdout = sys.stderr

(01 Dec '11, 14:13) tclancy

That is the usual location. You can check your /home/<username>/webapps/<appname>/apache/conf/httpd.conf file to confirm the location as well.

permanent link

answered 30 Nov '11, 11:48

bmeyer71 ♦♦
1.5k3613
accept rate: 33%

They are in /home/username/logs/user with whatever name they're given in the Apache conf file. By default they are appname_access_django_log and appname_error_django_log

Not that you asked, but you probably want to look at Django's logging code or something like Sentry, which will let you log to that and view the results in a nice web app that's secured to Django admins. It's cleaner, easier to manage and less likely to break WSGI which doesn't like you sending stuff to stdout.

permanent link

answered 30 Nov '11, 13:42

tclancy
861615
accept rate: 6%

edited 30 Nov '11, 13:42

I see files of a different pattern, and the print statements above don't show up. The view access is logged, but not the print statements:

[bnesbitt@web309 user]$ cat /home/bnesbitt/webapps/django/apache2/conf/httpd.conf CustomLog /home/bnesbitt/logs/user/access_django.log combined ErrorLog /home/bnesbitt/logs/user/error_django.log

[bnesbitt@web309 user]$ ls -1 /home/bnesbitt/logs/user access_django.log access_django.log.1 error_django.log error_django.log.1

(01 Dec '11, 00:53) brycenesbitt

Note the topic is covered at: http://docs.webfaction.com/software/django/troubleshooting.html

(01 Dec '11, 01:06) brycenesbitt
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×13

question asked: 30 Nov '11, 11:05

question was seen: 6,335 times

last updated: 01 Dec '11, 14:13

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM