[pgrouting-dev] New logger for C/C++ for pgrouting
Stephen Woodbridge
woodbri at swoodbridge.com
Sun May 4 12:19:09 PDT 2014
Hi Devs,
Update the pgr_logger.h and added PGR_ prefix to all the macros to avoid
potential confusion. I also updated the vrp_basic cpp code to use the
new logging facility.
Here is the updated documentation:
USAGE:
#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
#include 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("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
-Steve
On 5/4/2014 2:06 PM, Stephen Woodbridge wrote:
> Hi Devs,
>
> I have created a new very simple header file at:
>
> pgrouting/src/common/src/pgr_logger.h
>
> The goal for this is to provide a consistent way for adding debug
> messages to the C/C++ that get directed to a log file. There is a define
> that can be used to globally disable the logging on a per file basis.
>
> I looked at a lot of other loggers for C/C++ but this seems to be good
> for our modest needs and it is easy to disable when we are ready to
> deploy it.
>
> Let me know you thoughts and please use it for the C++ code. You can
> also use this for the C code, but most of the C code already is using
> postgresql elog() function to send NOTICE statements back to the client.
>
> Thanks,
> -Steve
>
> READ the header file it has documentation in it.
>
> USAGE:
>
> #define LOGGERR_ON
> #undef LOGGER_ON // turn off logging for production
>
> // override the default log file "/tmp/pgr_logger.log"
> #define LOGGER_FILE "mylogger.log"
>
> #undef LOGGER_LOC // dont log filename and line number
> #define LOGGER_LOC // log filename and line number with log message
>
> // include the logger macros and configure based on defines above
> #include pgr_logger.h
>
> // log a message to the log file
> LOG(format, args)
> LOG("%s at %d\n", "this is a message", time())
>
> This will log something like:
>
> myfile:123: this is a message at 1399216875
>
> _______________________________________________
> pgrouting-dev mailing list
> pgrouting-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/pgrouting-dev
More information about the pgrouting-dev
mailing list