Question

I am implementing a log server in C++; that accepts log messages from a Java program (via log4j socket appender). How do I read these java logging objects in C++?

Was it helpful?

Solution

You should configure the log4j appender to send XML format messages. Then it is simply a matter of reading XML in C++.

OTHER TIPS

Serialized java objects is a byte stream which need meta information from the Java Runtime to be able to reconstruct the java objects. Without that meta information available in the system you must add that information yourself, which is tedious and error prone. I second the idea of sending XML instead - that is what XML serialization was invented for :)

Another very fast way of language-agnostic serialization is protobuf. proto-files (meta-files that describe your data-structures) are compiled using protoc which writes IO-code for various target languages.

I'm using it in my app and did some benchmarking which might give you a clue if it serves your purpose. The only downside I'm aware of is that protobuf does not handle references at all. If one of your objects contain the same object twice it will be written twice instead of just once with a reference to the previous instance (which is the case with Java serialization).

Concerning your original question, I agree with Thorbjørn that reading and writing of serialized Java objects will be too hard and error prone.

If you consider going the protobuf way, feel free to use this logging event protobuf file as a starter.

json is the best way to go for this kind of problems.

Log4cxx is a Log4j port to C++, perhaps you can glean some ideas from that or even use it directly?

JSON! JSON! JSON! JSON!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top