CAF Application logging using log4j

I am working on a CAF application in WM7.1 and my requirement is to log all application specific logs (debug, info, warn, fatal) in a separate application log file. I tried using my own log4j jar & log4.properties file within my CAF application but no information is getting logged (may be ClassLoader issue). I would appreciate all help on configuring logging in 7.1 CAF application using log4j. Some information I am looking are as below

  1. Where to configure logger, appender & layout information. (is it log4j.init.properties file)
  2. API to retrieve logger & log (debug, info, warn & fatal) messages from my CAF application.

Thanks in advance

Please look at the following thread:

http://sag.forums.softwareag.com/viewtopic.php?t=12626&highlight=CAF+log4j

Thanks Alex for the reply. But I can’t access the link. Even though I am registered with the internal sag forum, I can’t see any forum list. I guess you need to provide me access to the forum.

From: Norman, Eric
Sent: Wednesday, July 02, 2008 11:32 AM
To: Imel, Mark; RnD-wM-CAF-SWAT
Subject: RE: Do we have an example of log4j configuration for CAF Standalone apps?

It

Thanks Alex!!
I made it work by directly adding a named logger to log4j.init.properties file of MWS/server/config folder. It is working as expected (Not sure if it is recommended way…).

I did put my log4j.jar in WEB-INF/lib folder & log4j.properties in WEB-INF/classes folder in MWS server expecting the application Classloader to load the appropriate file but nothing was getting logged. I will give it a try again.

Anyways thanks for your prompt response and I really appreciate all your help.

Sandeep, did you work out how to do it? Can you please tell me? It’s not working for me.

Hi,

    We also use custom loggers for our applications.

    A log4j jar file alredy exists by default in [b]webMethods7/common/lib/ext/log4j.jar[/b]. I [b]think [/b]MWS & IS uses this jar.

    In order to use a custom logger  for our applications we have made the following configurations:

    - in the file [b]MyApp\WebContent\WEB-INF\web.xml[/b] add the following listener:
	<listener>
		<listener>com.myapp.util.MyServletContextListener</listener>
	</listener>
    - create the class [b]com.myapp.util.MyServletContextListener[/b]:
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.PropertyConfigurator;

public class MyServletContextListener implements ServletContextListener {

  public void contextDestroyed(ServletContextEvent arg0) {
    // do nothing
  }

  public void contextInitialized(ServletContextEvent arg0) {
    try {
      // Set Logggingproperties with Configfile
      PropertyConfigurator.configureAndWatch(arg0.getServletContext().getRealPath(
          "/WEB-INF/" + "myLog4j.properties"),5 * 1000);
    } catch (Exception e) {
      e.printStackTrace();
    }

  }

}
   - create your own [b]myLog4j.properties[/b] file
- use the logger in your application:
private static Logger myLogger = Logger.getLogger(Foo.class);

br,
Vlad