At 03:25 PM 8/23/2003 -0400, [EMAIL PROTECTED] wrote:




Hi all, I'm trying to work with JBoss and Log4J, and have run
into a question that I can't seem to find the answer to. In the
course of trying to figure out how to specify "per-application"
Log4J configuration for web-apps running under JBoss,
I found this reference to the RepositorySelector mechanism:
https://www.qos.ch/logging/sc.html

What I don't know however is:

1. Does JBoss even support this mechanism?

Is JBoss written in Java? Yes, I think it is. Yep, it is supported. Repository selectors just need some unique characteristic that can differentiate logger repositories. There are a couple of different obvious choices to use. One is keying on different classloaders. The other, under a J2EE environment, is keying on a JNDI namespace. Obviously, both of these can be used in JBoss since it uses classloaders and is a J2EE container.


2. If so, how do I utilize it in my client code, to retrieve the app
specific
    Log4J instance?

My initial thought, based on a quick perusal of the javadoc gives me the
idea I'd need something like this:


public class ControllerServlet { private static Logger logger; private ServletConfig config;

      public void init(ServletConfig config ) throws ServletException
      {
            this.config = config;
            LoggerRepository repos = LogManager.getLoggerRepository();
            logger = repos.getLogger( (ControllerServlet.class
).toString());

}

      <snip>
}


is this anything close to correct?

It is actually easier than that. Your logger code doesn't need to change at all. Just. Once the logger repository selector is used in the initialization of Log4j, you will be using a unique logger repository.


3. assuming the above (or something similar) is used to retrieve the app
specific instance of Log4J,
   is there anything special I need to do to tell Log4J where to find the
app-specific log4j.xml?  Or is
simply putting log4j.xml under WEB-INF/classes sufficent?  Would I still
need to call DOMConfigurator.configure()?

If you use the default initialization mechanism, you will be logging in the default logger repository. If you put both log4j.jar and your log4j.xml in the webapp's WEB-INF/lib and WEB-INF/classes, then you should be able to use this mechanism since the servlet spec makes it so that the webapp class loader is checked first for classes and resources. Only after that does it check parent classloader. Note that this is converse to the normal Java2 class loader hierarchy. If you put log4j.jar in a parent classloader (outside of WEB-INF/lib), however, you will need to use a repository selector to keep your logging separated from other apps.



4. is there any configuration at the JBoss level that needs to be done to
support app-specific Log4J
instances? I know about the log4.xml under server/default/conf/ which
specifies the "global" Log4J
properties for the container itself...  it wouldn't need to be touched for
this would it?

Not entirely sure about JBoss specifics, but if you put log4j.jar in WEB-INF/lib, that jar will be loaded by the webapp rather than the jar provided by the global JBoss classloader (although I'm not totally sure about JBoss' single classloader scheme, but it seems that would violate the servlet spec if they didn't allow for a separate webapp class loader).


However, if you want to use the global log4j.jar and use separate logger repositories, try the servlet context listener and the custom repository selectors I wrote in the log4j-sandbox project. Read about that stuff here...
http://nagoya.apache.org/wiki/apachewiki.cgi?Log4JProjectPages/AppContainerLogging


Also, let me apologize in advance for the cross-post. I'm genuinely not
sure which list was the
best choice to post this question too.

Actually, you should send questions like this to log4j-user rather than log4j-dev since you have a question about Log4j's usage, not a Log4j's development, but I'll let it slide this time :-)


Jake


Thanks,

Phillip Rhodes
Application Designer
Voice Data Solutions
919-571-4300 x225
[EMAIL PROTECTED]

No citizen shall be denied the right to bear arms, if as a last resort, to
protect themselves from tyranny in Government. - Thomas Jefferson

....except crazy Republicans. Thomas Jefferson couldn't have foreseen their ilk :-)



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



------------------------------------------------------- This SF.net email is sponsored by: VM Ware With VMware you can run multiple operating systems on a single machine. WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the same time. Free trial click here:http://www.vmware.com/wl/offer/358/0 _______________________________________________ JBoss-Development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to