File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Websphere and the fly likes Log4j and WSAD 5.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Log4j and WSAD 5.0" Watch "Log4j and WSAD 5.0" New topic
Author

Log4j and WSAD 5.0

xin wen
Ranch Hand

Joined: Oct 11, 2002
Posts: 64
Hi,
I am trying to use Log4J for logger in my project. I downloaded it from Log4J website, and copy the log4j.jar to my project, but it seems like did not work well. When I test it, (logger.debug("ENTRY")), I go back to myapplication.log file, nothing in there, so I wander if I need to do some configuration on WSAD or add some log4j config files, do not know here, does anyone know this?
Thanks all so much!
rahul V kumar
Ranch Hand

Joined: May 20, 2003
Posts: 82
I have used Log4j with Websphere 4.0.5 & Websphere 5.0 and i had no problems with that.
I have put the jar in my lib, and configuration file was in WEB_INF/classes
make sure its reading your configuration file (incase you have one)
[ June 13, 2003: Message edited by: rahul V kumar ]
xin wen
Ranch Hand

Joined: Oct 11, 2002
Posts: 64
Thank you rahul for the reply.
I want to make sure that is the configure file which you mentioned the log4j.properties?
Thanks
xin wen
Ranch Hand

Joined: Oct 11, 2002
Posts: 64
Hi,
I still cannot make it work. I deleted the log file, when I ran the project this time, the log file was not generated at all, do not know why. I wander if the common-loggins.jar which is the log jar WSAD itself causes this to be happen, so is that the reason it does not load my .properties file properly? Anyone had this problem before?
Thanks
rahul V kumar
Ranch Hand

Joined: May 20, 2003
Posts: 82
1) I am using log4j-1.2.8.jar
2) Import this jar file into your WEB_INF\lib directory
3) I have writter a wrapper class for Log4J and I have placed it in package log under Java Source
I am pasting some sample code here.
**********************************************
Java Source\log\Logger.java
**********************************************
package log;
import org.apache.log4j.*;
import java.util.*;
import java.io.*;
import java.net.*;
/**
* This is a wrapper class for Log4J.
*/
public class Logger {
Category cat;
// Logger class name
static String Nm = Logger.class.getName();
/** Constructor which returns the root content
*/
public Logger() {
cat = Category.getRoot();
}
/** creates an instance of the desired class name
* @param name of class
*/
public Logger(Class name)
{
cat = Category.getInstance(name.getName());
}
/** Configuration settings
* @param propsFile full path name of properties file
* @param refresh in milliseconds. This reads the properties file at the specified intervals.
*/
public static void configureAndWatch(String propsFile, int refresh) {
PropertyConfigurator.configureAndWatch(propsFile,refresh);
}
/** log a debug message
* @param msg
*/
public void debug(String msg)
{
cat.log(Nm,Priority.DEBUG,msg,null);
}
/** log a debug message
* @param msg
* @param t a Throwable
*/
public void debug(String msg,Throwable t)
{
cat.log(Nm,Priority.DEBUG,msg,null);
}
// do similar for info,fatal,error and warn
}

************************************************
5) It should compile without any errors.
6) I have got this settings file in my local C:\. You can place it anywhere you want.
***********settings.prop*****************
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
#log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
#log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
#log4j.appender.A1.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.A1.layout.ConversionPattern=%d [%-5p] (%F:%L) - %m\r\n
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=C:\\mylog.log
*****************************************
7) I am now using this Logger from my JSP Page which is under Web Content
**********LogTest.jsp***************
log.Logger logging =new log.Logger(log.Logger.class);
logging.configureAndWatch("C:\\settings.prop",3);
logging.debug("test test test message");

************************************
Good luck !!!
Originally posted by xin wen:
Hi,
I still cannot make it work. I deleted the log file, when I ran the project this time, the log file was not generated at all, do not know why. I wander if the common-loggins.jar which is the log jar WSAD itself causes this to be happen, so is that the reason it does not load my .properties file properly? Anyone had this problem before?
Thanks
xin wen
Ranch Hand

Joined: Oct 11, 2002
Posts: 64
I will try it, thanks for helping me.
 
Don't get me started about those stupid light bulbs.
 
subject: Log4j and WSAD 5.0