Developer How to debug - pgRouting/pgrouting GitHub Wiki

Debug Output

For C code you can use look in most all of our wrapper C code and see how to add #define DEBUG blocks to get access to DBG(...): macro that will output messages to as postgresql NOTICE messages.

If you want to log messages to a log file we have a simple mechanism that works in C or C++ as follows. Assuming you code is in src/<feature>/src/{code.c, code.cpp} then you can include the follow in your source file:

#define PGR_LOGGERR_ON
#undef PGR_LOGGER_ON  // turn off logging for production

// override the default log file "/tmp/pgr_logger.log"
#define PGR_LOGGER_FILE "mylogger.log"

#undef PGR_LOGGER_LOC  // dont log filename and line number
#define PGR_LOGGER_LOC  // log filename and line number with log message

// include the logger macros and configure based on defines above
// this is assuming your code is in the tree like: src/<feature>/src/{code.c,code.cpp}
#include "../../common/src/pgr_logger.h"

// log a message to the log file
// PGR_LOGF(format, args);
PGR_LOGF("%s at %d\n", "this is a message", time());

// PGR_LOG(str)
PGR_LOG("just print a string to the log");

This will log something like:

myfile.cpp:123: this is a message at 1399216875
myfile.cpp:124: just print a string to the log

This should work in c or C++ and you can do a tail -f on the log file in another window (on Linux) to see your progress.

Rebuild PostgreSQL

If you build your own Postgresql you might want to rebuild it with --enable-cassert option to configure, which will put the database backend into a more rigorous memory check mode.

Example for Debian/Ubuntu environment:

sudo /etc/init.d/postgresql stop
apt-get source postgresql-server-dev-9.2
sudo apt-get build-dep postgresql-server-dev-9.2
dpkg-source -x postgresql-9.2_9.2.4-1.pgdg60+1.dsc
cd postgresql-9.2-9.2.4/
DEB_BUILD_OPTIONS="--enable-cassert --enable-debug" fakeroot debian/rules binary
DEB_BUILD_OPTIONS="--enable-cassert --enable-debug" debian/rules binary
DEB_BUILD_OPTIONS="--enable-cassert --enable-debug" fakeroot debian/rules binary
cd ..
sudo dpkg -i postgresql-server-dev-9.2_9.2.4-1.pgdg60+1_i386.deb
sudo /etc/init.d/postgresql start
⚠️ **GitHub.com Fallback** ⚠️