commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Morreale <bmorr...@gmail.com>
Subject Re: [Logging] : Can commons.logging be used without log4j
Date Mon, 23 Aug 2010 03:18:58 GMT
Jasmin Mehta <Jasmin.Mehta <at> nexweb.org> writes:

> 
> Brent,
> 
> I could write up log4j.xml and implement RepositorySelector  as you 
> suggested in the URL. 
> 
> But still my logs are going to the same log file for 2 web applications 
> deployed on the same OC4J instance.
> 
> I have OC4J Application server 10.1.3.5.0 where I have deployed 2 web 
> applications on the same instance, and the logs for both applications are 
> going to only one log file which got deployed first. 
> 
> log4j-1.2.16.jar is in use as a shared-lib for the instance.
> 
> How can I separate them?
> 
> Thanks
> Jasmin
> 
> From:   Brent Worden <brent.worden <at> gmail.com>
> To:     user <at> commons.apache.org
> Date:   08/09/2010 09:56 AM
> Subject:        Re: [Logging] : Can commons.logging be used without log4j
> 
> On 8/9/2010 7:53 AM, Jasmin Mehta wrote:
> > The log4j has limitation that if its used as a shared library then it 
> can
> > initiate only one configuration. So my all we applications which shares
> > the same instance are populating the logs into only one log file (the 
> web
> > app which deployed first in order), rather than individual / separate 
> log
> > files configured in the path of each of the application's
> > log4j.properties.
> >
> >
> This isn't true.  Log4j allows for defining and using multiple log
> configurations in a single JVM.  This is accomplished by using a
> RepositorySelector to manage the multiple log hierarchies.  See
> http://community.jboss.org/wiki/Log4jrepositoryselector for a web
> container example.
> 
> Thanks,
> 
> Brent Worden
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe <at> commons.apache.org
> For additional commands, e-mail: user-help <at> commons.apache.org
> 
> ******************************************************************************
> This email and any files transmitted with it are intended solely for 
> the use of the individual or agency to whom they are addressed. 
> If you have received this email in error please notify the Navy 
> Exchange Service Command e-mail administrator. This footnote 
> also confirms that this email message has been scanned for the
> presence of computer viruses.
> 
> Thank You!            
> ******************************************************************************
> 
> 

Hi Jasmin, sounds like OC4J is once again having issues with open-source based
components. I have a suggestion, in addition to providing each web app with
their own log4j.properties file, add a simple servlet to provide each
web instance a log4j initialization path. This will provide a very detailed
control over the log file produced (location/levels).

For example:

package com.foo;

import org.apache.log4j.PropertyConfigurator;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.io.IOException;

public class Log4jInit extends HttpServlet {

  public void init() {
    String prefix =  getServletContext().getRealPath("/");
    String file = getInitParameter("log4j-init-file");
    // if the log4j-init-file is not set, then no point in trying
    if(file != null) {
      PropertyConfigurator.configure(prefix+file);
    }
  }

  public
  void doGet(HttpServletRequest req, HttpServletResponse res) {
  }
}

Define the following servlet in the web.xml file for your web-application(s).

  <servlet>
    <servlet-name>log4j-init</servlet-name>
    <servlet-class>com.foo.Log4jInit</servlet-class>

    <init-param>
      <param-name>log4j-init-file</param-name>
      <param-value>WEB-INF/classes/log4j.lcf</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
  </servlet>

Writing an initialization servlet is the most flexible way for initializing
log4j. There are no constraints on the code you can place in the init() method
of the servlet.


then in all classes to log:

private static Logger log = Logger.getLogger(<class name>.class);


- Brian Morreale



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


Mime
View raw message