The following code shows how to organize debug printing with minimal impact on the loaded system
#include <syslog.h> #include <stdarg.h> #include <stdlib.h> static void print_at(const char *srcfile, int line, const char *format, ...) { va_list ap; const char *envvar="JAVA_SHOULD_PRINT_AT"; static int requested_line = -1; if (requested_line == -1) { const char *should_print = getenv(envvar); requested_line = (should_print != NULL) ? atoi(should_print) : 0; openlog("javadebug", LOG_PID, LOG_UUCP); } if (requested_line == line) { va_start(ap, format); vsyslog(LOG_DEBUG, format, ap); va_end(ap); } }