Site5 - Built For Designers & Developers MENU

How can I redirect stderr to error log?

[3 Grey Star Level]

On my local development machine, I catch and post errors to stderr, which is then redirected to my local error log. When I update my Site 5 site, there shouldn’t be any errors … but, of course there are.

Unfortunately, my error log tells me that an error occured, but not what the error was:

[Sat Jun 16 11:18:38 2012] [warn] [client 71.34.53.115] mod_fcgid: stderr: File “/home/jimdscot/public_html/hoops_web.py”, line 141, in GET, referer: http://www.jimdscott.com/choops
File “/home/jimdscot/public_html/hoops_web.py”, line 151, in _do_work
File “/home/jimdscot/public_html/hoops_web.py”, line 131, in GET

In these modules, the error is being caught and written out to stderr. Is there a way to get the output to stderr included in my error log?

Answer #1

When dealing with a script issue the best way to get the error output is to simply execute the file that is having issues on the server itself. In this case, the hoops_web.py is erroring out so if you login via SSH to your account and execute the script it will return the actual error.

I can see by your account that the script is already chmod’d to 755, so running it by typing the following into my bash terminal returns the following error:

[~/public_html]# ./hoops_web.py

./hoops_web.py: line 19: syntax error near unexpected token `(‘
./hoops_web.py: line 19: `urls = (‘

In this way you can see that there’s a syntax error on line 19 of the script which will need to be resolved before it’ll work as intended.

Now, in regards to redirecting the stderr output to a file, you can do this by simply executing the script like so:

[~/public_html]# ./hoops_web.py 2> error.log

By appending the 2> error.log you’re telling bash that you want to redirect the stderr output to the file error.log, which you can then open in your text editor of choice.

I hope that helps.

Answers Answered By: Ronald [6 Grey Star Level]

Answer #2

Thanks for taking the time to reply. The script isn’t intended to be run from the command line, so I expect you would always get an error trying to run it as a standalone script.

The error was actually a database permission issue. This was throwing a python error, which I was trying to catch and route to the Apache error log via writing to stderr. I understood that by default, anything written to stderr would be included in the Apache error log. This works on my Mint testing box, but doesn’t seem to work on the Site5 server.

I got around the issue by dumping the error into the JSON return value for the call. I was able to view the error in the JavaScript debugger and resolve the problem.

Answers Answered By: jimdscott [3 Grey Star Level]

Answer this Question

You must be Logged In to post an Answer.

Not a member yet? Sign Up Now »

Money Back Guarantees
Click to verify BBB accreditation and to see a BBB report.