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