Handling newlines in log entries

Notes, tips, and other usefull things on how to use LogMX

Moderator: admin

Post Reply
isheedm
Posts: 109
Joined: Wed Sep 12, 2007 2:16 pm

Handling newlines in log entries

Post by isheedm »

I am using LogMX 3.0.1 with a Simple Parser that I setup. The format is fields seperate by pipe characters "|". If an exception is logged, it goes on the next line. However, not all messages will have exceptions.

At the moment, the exceptions are ignored. I'd like them added to the Message. The current format is:

{{Level}}| {{username}}| {{Message}}| {{Timestamp}}| {{Emitter}}| {{method}}

(P.S. I'd like a way to easily copy/paste that definition)

I can modify the order of the fields if necessary in my logger definition if that is an easy workaround.

Example text with 2 messages: (first has no stack trace, second one does)

Code: Select all

INFO| user1| User login successfull: dom1\user1| Feb 15, 2012 5:08:33 PM| aaa.bbb.CCCC| startup
SEVERE| user1| Error checking DB version!| Feb 15, 2012 5:08:35 PM| aaa.bbb.CommonUtilities| get_Version
java.lang.IllegalArgumentException: NamedQuery of name: FooProperty.findByKeyword not found.
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:571)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameterInternal(EJBQueryImpl.java:1190)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:1079)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:73)
admin
Site Admin
Posts: 555
Joined: Sun Dec 17, 2006 10:30 pm

Re: Handling newlines in log entries

Post by admin »

Hello,

I suggest you to make the "Message" field the last field on your line, so that handling exceptions stacks will be automatically performed by LogMX. In this case, the following Log4j Pattern Parser works pretty good:

Code: Select all

%p| %u{username}| %d{MMM dd, yyyy H:m:s aa}| %c| %M| %m
(be careful when copy/pasting this pattern, no white-space character should be present before or after this pattern)

Here is an example of parsed log:
INFO| user1| Feb 15, 2012 5:08:33 PM| aaa.bbb.CCCC| startup| User login successfull: dom1\user1
SEVERE| user1| Feb 15, 2012 5:08:35 PM| aaa.bbb.CommonUtilities| get_Version| Error checking DB version!
java.lang.IllegalArgumentException: NamedQuery of name: FooProperty.findByKeyword not found.
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:571)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameterInternal(EJBQueryImpl.java:1190)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:1079)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:73)
INFO| user1| Feb 15, 2012 5:08:33 PM| aaa.bbb.CCCC| startup| User login successfull: dom1\user1
SEVERE| user1| Feb 15, 2012 5:08:35 PM| aaa.bbb.CommonUtilities| get_Version| Error checking DB version!
Let me know if you have problems with this Parser.

Xavier.
Post Reply