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:
int log_output_to_file(genptr_t data, genptr_t str)
FILE *fp = (FILE *)data;
fprintf(fp, "LOG: %s", str);
int main(int ac, char *av)
FILE *fp = fopen("whatever.log", "w+");
bu_log("Logging to file.\n");
bu_log("Logging to stderr.\n");
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.