I would not like to use setOut() because it's a global variable. You'll run into "action at a distance": you want to intercept stdout just for this library, but not to trample on anything else that might need to use stdout.
If at all possible, run the code that calls the library functions in a separate process space; then you can write a thread that reads stdout from that process and send to a logger.
new Thread() {
public void run() {
ProcessBuilder pb = new ProcessBuilder(command);
Process p = pb.start();
BufferedReader in = new BufferedReader(p.getInputStream());
String line;
while ((line = in.readLine()) != null) {
log.info(line);
// or you could parse line and try to dynamically pick a log level
}
}
}
You'll need a good way to get output from the called process back to your caller, but if it's as simple as returning a value, then it ought to be easy to return that as the last line of your stdout, or a line with a special signal code, or something.