I have a C++ application and a Java application that need to log messages in the same way. My Java application uses Apache Commons Logging, backed by a Log4j configuration. I need a single log4j configuration so I can change my logging preferences in one location. In my C++ application, I have captured all calls to printf() and fprintf(std***) and am thinking I have the following options:
Fork in my C++ app, create a pipe from (f)printf() calls to the new processes stdin, and start a Java program that reads from stdin and logs using Commons Logging
Create a JVM in the C++ app using JNI's JNI_CreateJVM() and invoke a Java logging method when the (f)printf() calls are made
Use something like Log4cxx to read the same configuration as the Java app and log natively in C++
I'd like to avoid option 3 as much as possible because I don't want to add another third-party dependency to my applications. I understand there is a performance cost to crossing from C++ to Java, but I'm not sure if it will matter that much.