I have configured log4j 2 with this config file to write my MapMessage
to console:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="ERROR">
<Properties>
<Property name="disableThreadContext">true</Property>
<Property name="disableThreadContextStack">true</Property>
<Property name="disableThreadContextMap">true</Property>
<Property name="log4j2.disable.jmx">true</Property>
</Properties>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<JsonLayout locationInfo="true" complete="false" />
</Console>
</Appenders>
<Loggers>
<logger name="ir.cvas.logger" level="info" />
<Root level="warn">
<AppenderRef ref="CONSOLE"/>
</Root>
</Loggers>
</Configuration>
The output of this configuration is like:
{
"timeMillis" : 1404902036494,
"thread" : "main",
"level" : "ERROR",
"loggerName" : "ir.cvas.log4j.json.Main",
"message" : "description=\"I'm so fucked...\" id=\"12312312312312321\"",
"endOfBatch" : false,
"loggerFqcn" : "org.apache.logging.log4j.spi.AbstractLogger",
"source" : {
"class" : "ir.cvas.log4j.json.Main",
"method" : "main",
"file" : "Main.java",
"line" : 24
}
}
- I need to remove some fields from output such as
endOfBatch
andloggerFqcn
. Is it possible? - I don't really like how
MapMessage
is converted. I would want something like Json object instead of single string, Something like thisthis:"message": { "description"="I'm so fucked...", "id"="12312312312312321" }
or at least flattenMapMessage
fields in to log message. - I want to convert timestamp field to unix time with milliseconds removed.
Can anyone help?