Debugging GeoNode’s Python Components¶
Logging is controlled by the contents of the logging data structure defined in
settings.py. The default settings distributed with GeoNode are
configured to only log errors. During development, it’s a good idea to override
the logging data structure with something a bit more verbose.
In production, logging output will go into the apache error log. This is located
/var/log/apache2/error.log. During development, logging output will,
by default, go to standard error.
- Ensure the ‘console’ handler is at the appropriate level. It will ignore log messages below the set level.
- Ensure the specific logger you’d like to use is set at the correct level.
- If attempting to log SQL, ensure
- To trace all SQL in django, configure the
- To examine a specific query object, you can use the
- You can gather more information by using
DEBUGis enabled, query SQL and timing information is stored in this list.
Don’t use print statements. They are easy to use in development mode but in production they will cause failure.
Take advantage of python. Instead of:
logging.info('some var ' + x + ' is not = ' + y)
logging.info('some var %s is not = %s', x, y)
- Enable logging of all SQL statements. Visit some pages and view the logging output.
- Using the python shell, use the
queriesobject to demonstrate the results of specific queries.
For the adventurous,
pdb allows for an interactive debugging session. This
is only possible when running in a shell via
manage.py runserver or
To set a breakpoint, insert the following code before the code to debug.
..code-block:: pythonimport pdb; pdb.set_strace()
When execution reaches this statement, the debugger will activate. The commands are noted in the link above. In addition to those debugger specific commands, general python statements are supported. For example, typing the name of a variable in scope will yield the value via string coersion. Typing “n” will execute the next line, “c” wil continue the execution of the program, “q” will quit.