struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mathew, Manoj" <Mathew.Ma...@principal.com>
Subject RE: log4j setup
Date Wed, 24 Sep 2003 14:11:42 GMT
Hi

there are three ways( known to me) to load the log4j at the server startup
 1.Create ur own servlet put the code in Init()and load it at the begining of your application
 2.Extend Action Servlet
 3.  through the following way.

I find the 3rd one better because it sound like struts way of doing it...!!
  this is what we have done..

in struts config
<!-- ========== Plug Ins Configuration ================================== -->
	<plug-in className="com.ff.gg.e.l.gi.ApplicationStartup" />

</struts-config>

ApplicationStartup.java

public class ApplicationStartup implements PlugIn {

	public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {
		try {
			ProposalLogger.configureLog4J();
			Category cat = Category.getInstance(ApplicationStartup.class);
			cat.info("log4j has been properly configured on application startup.");
		} catch()


this will load and configure your log$j each time you start your server..

then i have a class which handle the logging..

public final class MylLogger {
	public static String LOG4J_PROPERTIES_FILENAME_TEST = "proposalLog4j.mytest.properties";
		public static void configureLog4J() {
		
			String filename = LOG4J_PROPERTIES_FILENAME_TEST;
		try {
			java.io.InputStream is = ProposalLogger.class.getResourceAsStream(filename);
			java.util.Properties prop = new java.util.Properties();
			prop.load(is);
			PropertyConfigurator.configure(prop);
			is.close();
		} catch {}
		Category cat = Category.getInstance(ProposalLogger.class.getName());
		cat.info(" Log4J logging has been properly configured using file " + filename + ".");
		return;
	}
.......................
then I use these two these two methods do my logging..
public static void logError(Category category, String msg, CustomerLoggingInfo customerInfo)
{}
public static void logTiming(Class caller, long start, long end, String msg) {}

If anybody has any better idea please let us know.
thanks
manoj

-----Original Message-----
From: Davide Bruzzone [mailto:Davide.Bruzzone@ngt.com]
Sent: Wednesday, September 24, 2003 8:41 AM
To: Struts Users Mailing List
Subject: RE: log4j setup


Here are the steps:

- Make sure that the appropriate Log4J JAR file is in your /WEB-INF/lib
directory
- Put your log4j.properties file in /WEB-INF/classes
- Wherever you want to log, add the following code:

import org.apache.log4j.Logger;

...

// This is a private static attribute within the class
private static Logger logger = Logger.getLogger(<The name of the
class>.class.getName());

...

// When you want to log something...
logger.debug("Something...");

Hope this helps... If you need more information about the
log4j.properties file, etc., the Log4J site points to lots of great (and
very detailed) documentation that you can use as a starting point...

Cheers...

Dave Bruzzone

-----Original Message-----
From: Viral_Thakkar [mailto:Viral_Thakkar@infosys.com] 
Sent: Wednesday, September 24, 2003 7:23 AM
To: Struts Users Mailing List
Subject: log4j setup


Please let me know what are the steps one need to do to configure the
log4j.



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message