Better MDC support for Log4J parser

If you think LogMX needs a new useful feature!
Post Reply
kbelunek
Posts: 4
Joined: Tue Jan 07, 2014 5:08 pm

Better MDC support for Log4J parser

Post by kbelunek »

I am trying to parse Log4J log with this pattern:

Code: Select all

%d{ISO8601} | %-5.5p | %-16.16t | %-50.50C %4L | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
There is example of the log line:

Code: Select all

2014-03-20 11:47:28,193 | INFO  | NioProcessor-2   | hd.common.session.AbstractSession$1IoSessionCloser  294 | 26 - org.apache.sshd.core - 0.8.0 | Session null@/fd00:0:0:a40:a236:9fff:fe11:d745:40949 closed
The pattern contains three MDC values (%x pattern) and LogMC Log4J parser wizard tranlates the pattern like this:

Code: Select all

Timestamp | Level | Thread | Emitter Line | MDC - MDC - MDC | Message
The problem is that resulting table with parsed data contains only one "MDC" column with the value of the third (last) %x pattern. If I disable it, the MDC will contain second %x value.


Will it be possibe to enhance Log4J parser to support more MDC columns and use its pattern definition names? E.g. for this example the resultinh table will contain three columnts "bundle.id", "bundle.name" and "bundle.version" instead of single "MDC" column.

As a workaround I modified Log4j pattern provided to the LogMX to:

Code: Select all

%d{ISO8601} | %-5.5p | %-16.16t | %-50.50C %4L | %X | %m%n
This workaround put all content into MDC column but the values are not filterable separately.

Regards!
admin
Site Admin
Posts: 555
Joined: Sun Dec 17, 2006 10:30 pm

Re: Better MDC support for Log4J parser

Post by admin »

Hello,

I think you're right, LogMX shall surely create 3 different columns for these three %X{...}. We will have a closer look at Log4j specifications and fix this on our side if needed.

In the meantime, you can simply replace %X{...} with %u{...} to create these 3 different columns named "bundle.id", "bundle.name", and "bundle.version" (it will create 3 "userdefined fields").

I will let you know on this forum thread if we fix this in LogMX.

Xavier
admin
Site Admin
Posts: 555
Joined: Sun Dec 17, 2006 10:30 pm

Re: Better MDC support for Log4J parser

Post by admin »

Hello,

LogMX v5.0.2 is now released and includes (among many other things) a fix for this bug (a new column is now created for each %X{..}, with its matching name).

Xavier
Post Reply