Classification: UNCLASSIFIED Caveats: NONE An interesting question came up from the COVART folks where they were asking how to capture logging output, presumably from LIBBU and libraries that use LIBBU like LIBRT. It's a question that has come up before so I thought I'd offer a little code snippet to show just how that is done.
Unless it's (bad) code that's using a different logging mechanism, there is
a logging hook that can be registered for logging output. Simple pseudocode
example sans some basic error checking:
#include "bu.h"
int log_output_to_file(genptr_t data, genptr_t str)
{
FILE *fp = (FILE *)data;
fprintf(fp, "LOG: %s", str);
return 0;
}
int main(int ac, char *av[])
{
FILE *fp = fopen("whatever.log", "w+");
bu_log_add_hook(log_output_to_file, (genptr_t)fp);
bu_log("Logging to file.\n");
bu_log_delete_hook(log_output_to_file, (genptr_t)fp);
bu_log("Logging to stderr.\n");
fclose(fp);
return 0;
}
With LIBBU's logging interface, you can toggle things on and off and
register as many hooks (to perform simultaneous multistream logging) as
needed. You can pass in a pointer to pretty much anything for you to
utilize inside the callback. Simple and easy.
Now if it's a critical error message (e.g., a bu_bomb failure), you have to
do something different to prevent an abort. Even those, though, are
"catchable" events/outputs, akin to exceptions (see BU_SETJUMP). They will
also call any registered logging hooks.
Cheers!
Sean
Classification: UNCLASSIFIED
Caveats: NONE
smime.p7s
Description: S/MIME cryptographic signature
------------------------------------------------------------------------------ Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________ BRL-CAD Developer mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/brlcad-devel
