4

i am trying to use a log viewer (doesn't matter which one) to parse my log files.

my log4j pattern is this.

%p [%t] (%C{1}:%M():%L) %d{dd/MM/yyyy-HH:mm:ss,SSS} S:%X{serviceType} N:%X{requestID}- %m%n

the log viewers (at least the open source ones) need you to implement a pattern so they will be able to read the file.

for example: for the log4j pattern: %p [%t] (%C{1}:%M():%L) %d{dd/MM/yyyy-HH:mm:ss,SSS} - %m%n

the log viewer pattern would be: pattern= pattern=LEVEL [THREAD] (CLASS:METHOD():LINE) TIMESTAMP - MESSAGE

the example works well.

but i have not been able to parse the %X property in any way. i have seen there are property types NDC and PROP(key) but i seem to either miss use them or they are not related to the %X

so the question is how to implement the pattern so it will read the %X parameter.

thanks.

mtk
  • 13,221
  • 16
  • 72
  • 112
Gleeb
  • 10,773
  • 26
  • 92
  • 135
  • Can you see the value of key serviceType and requestID from the MDC in your normal log file? – Cygnusx1 Aug 30 '11 at 13:37
  • yes. but it is not used always. the value is empty at some places. – Gleeb Aug 31 '11 at 06:09
  • ok, thats normal... now, i don't know what log viewer you use? Did you check if this log viewer support the %X to read the MDC key/Values – Cygnusx1 Aug 31 '11 at 13:06
  • i am using otroslogviewer, its an open source. from what i see it supports NDC, not MDC. http://code.google.com/p/otroslogviewer/wiki/Log4jPatternLayout – Gleeb Aug 31 '11 at 13:17
  • Gleeb, have you tried to use newest version of OtrosLogViewer? Your pattern should looks like this: pattern= pattern=LEVEL [THREAD] (CLASS:METHOD():LINE) TIMESTAMP S:PROP(ServiceType) N:PROP(ReqID)- MESSAGE – KrzyH Oct 18 '11 at 09:27
  • thanks for the replay. this still doesn't work, the pattern you mentioned does not compile unless changing the '(' and ')' to '{' and '}' after the PROP value. i assume that your the owner of the application from the user name, if you would like, i could send you a log sample and the log4 file for you to analyze. tried with version 11.11.11 – Gleeb Nov 22 '11 at 12:43

1 Answers1

3

Ok, i think i see the problem.

Your application use the log4J MDC since it use the %X in the pattern layout. Your log viewer seems to support only NDC.

log4j pattern layout for NDC is %x (lowercase).

If you have control on the application, you have to change MDC -> NDC and modifiy the log4j.xml to use %x instead of %X. That may be a big task if the app is huge...

Another solution would be to find a log viewer that support MDC(%X)

I tried to look around for the PROP(key), but there is not much doc on it ;-(

Good luck

Cygnusx1
  • 5,329
  • 2
  • 27
  • 39
  • Ok, it doesn't work, MDC and MDC does not work the same way. its either to remove the use of MDC all together or find something else. that problem is that i haven't found any open source log viewer that supports MDC. – Gleeb Sep 01 '11 at 07:47