views:

28

answers:

2

I'm trying to make django work with wsgi in a shared hosting, so I cannot access server logs,

I'm trying to redirect the output to a file in my django.wsgi script, like this:

saveout = sys.stdout
log_out = open('out.log', 'w')  
sys.stdout = log_out 

but this is the error that I have (in the only error log that I can access)

[Thu Oct 07 19:18:08 2010] [error] [client <ip>]   File "/home/myuser/public_html/django.wsgi", line 9, in <module>
[Thu Oct 07 19:18:08 2010] [error] [client <ip>] mod_wsgi (pid=30677): Exception occurred processing WSGI script '/home/myuser/public_html/django.wsgi'.

and that is all the error I can get

Line 9 is the one that tries to open file. I've tried creating previously the file, giving writing access to everyone, without the file previously created.. and nothing. In the app, I only get a 500 server error.

Is there a proper way to get this output without access to apache logs?

Edited:

Using absolute paths, I can open files and write to them, but I get empty files unless I close the files in the end, is it necessary? Could I leave the files open?..

Regarding to the initial problem, even though I used exception handling, write a "finish ok" to file in the end of my script, then close the file, but still get the error:

[Thu Oct 07 13:33:07 2010] [error] [client <ip>] mod_wsgi (pid=32541): Exception occurred processing WSGI script '/home/myuser/public_html/django.wsgi'.

If I intentionally raise an error, it is logged in the file, so as i get "ok" I think the script worked fine but the result is still that message error... no clues

+2  A: 

You can't use relative pathnames like out.log in a WSGI application. WSGI doesn't specify where the working directory will be pointing and mod_wsgi doesn't set it unless specifically asked to in daemon mode.

Use an absolute pathname based on your application's root. You can use os.path.dirname(__file__) to get the directory containing the current script/module if needed.

bobince
That was part of the problem, thanks!
Sam
A: 

In the end, I solved the problem using a debugging tool as explained here:

http://www.davidcramer.net/code/502/debugging-django-errors.html

Sam