I need to log a custom object as plain JSON string, without any extra log event details. I tried to use .apache.logging.log4j.message.MapMessage
(solution is described here ), though it seems that it supports only one level flat JSON object, that doesn't have inner JSON objects. The MapMessage has put(String, String)
method that accepts only values that are strings, so there is no option to store a complex value, another Object. I also tried the with
method that accepts an Object, with("key1", obj)
, but it only prints what Object.toString() can print:
{"id1":"11111111-1111-1111-1111-111111111111","obj":"company.CustomLog$MyClass@3c80be62","id2":"22222222-2222-2222-2222-222222222222"}
In the documentation I read an interesting phrase, that I couldn't decipher (.12.x/manual/messages.html):
When an Appender is MessageLayout-aware, the object Log4j sends to target is not a Log4j Log Event but a custom object.
Does anybody has an idea about the possible implementation?