[398] | 1 | .. _services-debug: |
---|
| 2 | |
---|
| 3 | How To Debug ZOO Services |
---|
| 4 | ========================= |
---|
| 5 | |
---|
[406] | 6 | :Authors: Luca Delucchi |
---|
[562] | 7 | :Last Updated: $Date: 2015-02-09 15:26:31 +0000 (Mon, 09 Feb 2015) $ |
---|
[406] | 8 | |
---|
[398] | 9 | There are different ways to debug your services, the most used solutions are via web |
---|
| 10 | or via command line. |
---|
| 11 | |
---|
| 12 | Web |
---|
| 13 | ---- |
---|
| 14 | |
---|
[437] | 15 | Using the web request you can see any problem in the log file of Apache. |
---|
[398] | 16 | |
---|
[437] | 17 | On Unix system the log file is usually in ``/var/log/apache2`` and the relevant file |
---|
| 18 | is ``error_log``. A simple way to read the file is to use the ``tail`` command, |
---|
[398] | 19 | it permits to see the update of the file for each request :: |
---|
| 20 | |
---|
| 21 | tail -f /var/log/apache2/error_log |
---|
| 22 | |
---|
[437] | 23 | If the log is not clear enough you can add some more debug information to your code. You have to write |
---|
| 24 | to standard error. |
---|
[398] | 25 | |
---|
| 26 | Python |
---|
| 27 | ******** |
---|
[437] | 28 | Using Python, you can for example do this |
---|
[398] | 29 | |
---|
| 30 | .. code-block:: python |
---|
| 31 | |
---|
| 32 | import sys |
---|
| 33 | |
---|
[437] | 34 | #add this line when you want see an own message |
---|
[398] | 35 | sys.stderr.write("My message") |
---|
| 36 | |
---|
[406] | 37 | .. _web_javascript: |
---|
[398] | 38 | |
---|
[406] | 39 | Javascript |
---|
| 40 | ************ |
---|
| 41 | |
---|
[437] | 42 | You can user ``alert`` to print a string to standard error: |
---|
[406] | 43 | |
---|
| 44 | .. code-block:: javascript |
---|
| 45 | |
---|
[437] | 46 | // add this line when you want see an own message |
---|
[406] | 47 | alert('My message') |
---|
| 48 | // you can debug value of inputs, outputs or conf |
---|
| 49 | alert(inputs["S"]["value"]) |
---|
| 50 | |
---|
[437] | 51 | .. note:: If you try to pass an object it will only return ``[object Object]`` |
---|
[406] | 52 | |
---|
[398] | 53 | Command line |
---|
| 54 | -------------- |
---|
| 55 | |
---|
| 56 | It is possible to use the ZOO kernel ``zoo_loader.cgi`` also from command line. |
---|
[437] | 57 | This is really useful to debug in a deeper way your service: |
---|
[398] | 58 | |
---|
| 59 | .. code-block:: bash |
---|
| 60 | |
---|
[437] | 61 | # in order to use it you have to copy test_service.py and HelloPy.zcfg from |
---|
[398] | 62 | # the example services |
---|
| 63 | ./zoo_loader.cgi "service=wps&version=1.0.0&request=execute&identifier=HelloPy&datainputs=a=your name&responsedocument=Result" |
---|
| 64 | |
---|
[437] | 65 | Working this way you can use the standard debug system of the actual programming language used |
---|
| 66 | to develop your service. |
---|
[398] | 67 | |
---|
| 68 | GDB |
---|
| 69 | ***** |
---|
| 70 | From command line you can use also the command line tool `GDB <http://www.gnu.org/software/gdb/>`_ |
---|
[437] | 71 | to debug ``zoo_loader.cgi``, you have to run: |
---|
[398] | 72 | |
---|
| 73 | .. code-block:: bash |
---|
| 74 | |
---|
| 75 | # launch zoo_loader.cgi from gdb |
---|
| 76 | gdb zoo_loader.cgi |
---|
| 77 | # now run your request |
---|
| 78 | run "service=wps&version=1.0.0&request=execute&identifier=HelloPy&datainputs=a=your name&responsedocument=Result" |
---|
| 79 | |
---|
[437] | 80 | At this point you can ask help at the `ZOO mailing list <http://lists.osgeo.org/cgi-bin/mailman/listinfo/zoo-discuss>`_ |
---|
[398] | 81 | copying the result of the command. |
---|
| 82 | |
---|
| 83 | Python |
---|
| 84 | ********** |
---|
[437] | 85 | For Python, you can use ``pdb``, more info at http://docs.python.org/2/library/pdb.html |
---|
[398] | 86 | |
---|
| 87 | .. code-block:: python |
---|
| 88 | |
---|
| 89 | import pdb |
---|
| 90 | |
---|
[437] | 91 | # add this line when you want investigate your code in more detail |
---|
[406] | 92 | pdb.set_trace() |
---|
| 93 | |
---|
| 94 | Javascript |
---|
| 95 | ************ |
---|
| 96 | |
---|
[437] | 97 | You can use ``alert`` also to print in the console, more info in the :ref:`web_javascript` web section |
---|