Results 1 to 4 of 4
- 04-12-2011, 04:47 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Formatting of log message using log4j
Hello group,
I need to log the messages to a file, where each attributes of the log message should be of constant length.
output:
------
param1 param2 param3 [line 1]
pot test serve [ line 2]
The message attributes passed to the logger api is just a space seperated like
logMessage("param1 param2 param3"); logMessage("pot test serve");
I searched in log4j manuals, but could not figure out how to parse the %m so that to pad extra spaces to make the output as desired.
Any pointer as how to proceed ? .
- 04-12-2011, 06:57 AM #2
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
The format got deleted, the actual output should be
Hello123454<space><space><space>Test<space><space> <space>hi
ghg<space><space><space><space>ss11<space><space>< space>sssss
- 04-12-2011, 03:14 PM #3
Senior Member
- Join Date
- Nov 2010
- Location
- Delhi
- Posts
- 135
- Blog Entries
- 1
- Rep Power
- 0
You can do that programatically.
For this you need to know the maximum lenth of each column value.
If you know the maximum column length, then keep adding the values to a StringBuilder. Before adding just check the length of value and fill the difference with spaces.
Once you are done with complete line contents, pass on the stringbuilder object to log4j for logging.
I hope that makes sense to you.
- 04-13-2011, 08:12 AM #4
Member
- Join Date
- Apr 2011
- Posts
- 18
- Rep Power
- 0
use something like this in your log4J properties file:
log4j.appender.A2=org.apache.log4j.RollingFileAppe nder
log4j.appender.A2.File=/app/ibot/java.log
log4j.appender.A2.layout=org.apache.log4j.PatternL ayout
log4j.appender.A2.layout.ConversionPattern=<%d{ISO 8601}> %-5p %-15.50c{1} %m %n
log4j.appender.A2.MaxFileSize=10MB
log4j.appender.A2.MaxBackupIndex=10
more information on formatting can be found at:
PatternLayout (Apache Log4j 1.2.16 API)
Similar Threads
-
Problem on Log4j: How to include custom <filter/> into JBoss (log4j.xml)?
By holyjohn in forum Advanced JavaReplies: 1Last Post: 09-20-2010, 08:32 AM -
java message box, how to not show multiple message box with same title or content
By oohay in forum AWT / SwingReplies: 6Last Post: 06-04-2010, 08:43 PM -
formatting..
By sireesha in forum New To JavaReplies: 16Last Post: 06-26-2009, 07:11 PM -
How to insert a Linebreak in a log4j message?
By MJalbert in forum Threads and SynchronizationReplies: 1Last Post: 03-06-2008, 01:03 PM -
Formatting the date
By yuchuang in forum New To JavaReplies: 5Last Post: 05-07-2007, 06:08 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks