• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Log4j and WSAD 5.0

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will try it, thanks for helping me.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic