Created On:  30 March 2011

Problem:

I am having problems with my server side scripts, how do I debug them?

Resolution:

Here are some hints for debugging and testing server side scripts.
 
- You can find error messages produced by your scripts in the file smartscript-stderr.log. Look in the log directory under the directory in which you installed EnterpriseLink.
 
- Use the print statement for producing debugging output. EL Server automatically reroutes standard output to the file smartscript-stdout.log. Check the log directory under the directory where you installed EnterpriseLink. Be aware, however, that writing to a file this way is not thread-safe; it may cause problems when multiple concurrent users use your application: remove "print" statements when you deploy your application. Or, put your "print" statements in a function, where you can turn them all off.
 
- You can change where standard output and print sends its output by creating a class that implements the write method and assigning an instance of that class to sys.stdout. See the sys module in the Python standard library. An example of re-routing output:
class Router:
    def write(self, outstring):
        f = open('mylog.log', 'a')
        f.write(outstring)
        f.close()
import sys
sys.stdout = Router()
# Write something to the file mylog.log via stdout.
print 'All the leaves are brown, and the sky is grey.\\n'
 
- And, of course, you can open, write to, and close a file of your choice. For example:
f = open('mylog.log', 'a')
f.write("Let's twist again, like we did last summer.\\n")
f.close()
 
- There is a "Check syntax" operation in EL Builder. Right-click on a script in Scripts Library tree in Builder; select that operation from the context menu.