SharePointAds TextOnly

Friday, 19 June 2009

Java :Add Logger system

1. download log4j.jar file
2. Add into our Java project libraries
3. Create new properties file at root with name "" and copy and paste following code

# Log levels
# Uncomment the following line to enable full loggin for every class
#log4j.rootLogger=trace, stdout, R, stdout, R

# Console appender configuration
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

# Rolling File Appender
# Path and file name to store the log file.
# Keep one backup file
# Rolling File Appender layout
log4j.appender.R.layout.ConversionPattern=%d - %c - %p - %m%n

4. Add following code on class/web-page,

private org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(this.getClass());
log.debug( request.getRemoteAddr() + " This is Index page log ");

Note: request.getRemoteAddr() gives IP address where web page is called.

It stores the log file on 'C:\Program Files\Apache Software Foundation\Tomcat 6.0' with Demo.log file, creates all new logs with following formate
2009-06-06 20:29:02,562 - org.apache.jsp.index_jsp - DEBUG - 0:0:0:0:0:0:0:1 This is Index page log

If you want to use GUI to read logger files then use LogMX(v1.3.2).
1. Create new formate parser. Goto Tools > Option.
2. It opens new option window, Under Parsers tags create new parser formate .
3. It shows new 'Add a log file parser' window, under log4j pattern parser add new patter which is used in "".
4. It parse your logger file.

No comments:

Post a Comment