Logging

From PyWPS
Jump to: navigation, search

Logging, logs and more wood

How to debug and stuff...

Basic logging for debugging

Well logging is a "must" when it comes to debugging and developing, in PyWPS you can use the logging module anywhere in the code. Its enough to add something like this:

import logging
logging.debug("Something has been debugged")

In the section Installation it is explained that pywps.cfg file contains the path to the log file, something like this

debug=true # deprecated since 3.2, use logLevel instead
logFile=/etc/httpd/logs/pywps.log
logLevel=DEBUG

Therefore everytime the python interpreter finds logging.debug it will append the message into the pywps.log, as follows:

PyWPS [2010-08-25 17:39:00,499] DEBUG: Something has been debugged

This can be use to check variables or to pass any other information to the pywps log.

In the cfg file we have the logLevel parameter, in the case above extra information will be appended to the log file as defined internally in the API, for example in this debug mode the log file is appended with process import, with inputs sent to the server and WPS status update

 INFO: Status [processaccepted]: Process ultimatequestionprocess accepted
 PyWPS [2010-08-25 10:25:57,057] INFO: Status [processstarted][0.0]: Process ultimatequestionprocess started
 PyWPS [2010-08-25 10:25:57,068] INFO: Status [processstarted][0.0]: processstarted Preparing....
 PyWPS [2010-08-25 10:26:07,085] INFO: Status [processstarted][10.0]: processstarted Thinking.....
 PyWPS [2010-08-25 10:26:17,114] INFO: Status [processstarted][20.0]: processstarted Thinking.....
 PyWPS [2010-08-25 10:26:27,144] INFO: Status [processstarted][30.0]: processstarted Thinking.....
 PyWPS [2010-08-25 10:26:37,174] INFO: Status [processstarted][40.0]: processstarted Thinking.....
 PyWPS [2010-08-25 10:26:47,197] INFO: Status [processstarted][50.0]: processstarted Thinking.....
 PyWPS [2010-08-25 10:26:57,225] INFO: Status [processstarted][60.0]: processstarted Thinking.....
 PyWPS [2010-08-25 10:27:07,246] INFO: Status [processstarted][70.0]: processstarted Thinking.....
 PyWPS [2010-08-25 10:27:17,275] INFO: Status [processstarted][80.0]: processstarted Thinking.....
 PyWPS [2010-08-25 10:27:27,304] INFO: Status [processstarted][90.0]: processstarted Thinking.....
 PyWPS [2010-08-25 10:27:37,334] INFO: Status [processstarted][100.0]: processstarted Thinking.....

 PyWPS [2010-08-25 12:29:09,619] INFO: Setting PYWPS_PROCESSES from configuration file to /users/rsg/jmdj/workspace/pywps-3.2-soap/pywps/processes/
 PyWPS [2010-08-25 12:29:11,112] INFO: Following processes are imported: ['returner', 'dummyprocess', 'ultimatequestionprocess', 'complexVector', 'complexRaster', 'firstInstance', 'secondInstance', 'assyncprocess', 'bboxprocess', 'complexprocess', 'literalprocess', 
'noinputsprocess', 'GMLBuffer', 'reducer', 'histogramprocess']

Remote debugging (PyDev)

PyWPS is intended to be run in servers in some sort of distributed system / Service Oriented Architecture (SOA), therefore logging and debugging as explained above is not practical and/or professional.

Remote debugging is an interest way to debug, it follows the principle that a remote script being debug should stop at some point and report current variables to a server, and from the debug server it should be possible to evaluate the script.

There are several IDE plantforms that support remote debbuging, for example Eclipse (PyDev) and ERIC. Here it will only be explained the use of PyDEV inside the Eclipse plantform.

A good PyDev/Remote debugging tutorial can be found here also Portuguese speakers can give a look to the "PyDev e QIS" in the blog "Mapeando o Brasil" (here)

It's assumed that you have Eclipse installed (version 3.2) with PyDev plugin and that you are more or less familiar with Eclipse as IDE. If not, check the following tutorial on PyDev and Eclipse-Python . All the major Linux distributions have Eclipse packages in their repositories (Yum, Pacman etc)

The first step is to include the PyDev module debug path either to your PYTHONPATH, or to the script being debugged. The majority of examples prefer to include this path in the script being debugged. The PyDev path is located inside the eclipse plugins, this may change according to the install options and user configurations, the path can be indicated (in the script being) as follows:

sys.path.append("/home/user/.eclipse/793567567/plugins/org.python.pydev.debug_1.6.0.2010071813/pysrc/")

In this case the, PyDev is inside the .eclipse/ folder which is hidden, and can be missed by locating file tools.

After this path append, it is possible to import pydev module

import pydevd

From this point on, remote debugging is enabled on the script.

Next step is to activate the debugging server, this server runs inside the Eclipse IDE, in the PyDev view of Eclipse there should be the following buttons:

EclipsePydevDebugSrvButtons.png


If the buttons aren't present then it's necessary to configure the view as follows:

  • Right click on the too-bar
  • Select: Customize Perpective and then PyDev Debug
  • Enable the remote server buttons
Pydev buttons eclipse.png


The server can also be started/stoped from pydev menu present in the pydev view.

Back to the script, now everytime that you include the following command:

pydevd.settrace('localhost', port=5678, stdoutToServer=True, stderrToServer=True)

The script will stop and the variables will be reported to the remote debugging server running on the localhost machine, port 5678. These are default options, and a method call without arguments will result the same way

In Eclipse you will get something like this:

Pydev debugger.png

The script will stop when it finds pydevd.settrace(), all the current state variables/objects will be indicated in the left. The script will be in standby until the user uses the control buttons to go forward to to stop the script

Pydev debugger control buttons.png

If the variables aren't visible, probably the variable button that should be in the left bottom corner hasn't been activated:

Pydev debugger expression button.png


In this case the wpy.py was running as an Apache CGI and the script was launched using a KVP request in the browser, if the debugging takes to long the server will close the HTTP connection to the client.

--Wikiadmin 15:59, 10 January 2011 (UTC)