how to use log4j logger declared in Java side from a dll
We are using a dll with JNA in our java project. We would like the C code开发者_StackOverflow社区 to also log to our log4j log files, is there an easy way of doing this?
Not easily, really. I can think of a few ways
- call a Java program within your C code that just calls log4j (slow, you have to load up Java for each logging call)
- leave a Java process running that accepts log requests (communicate with the process using one of the options here Good alternative to shared memory IPC for Java/C++ apps on Linux)
- use GCJ to natively compile a Java program that calls log4j, then link it to your C program
精彩评论