[slf4j-user] Per-web-app logging with jars on the ser ver's classpath
Jacob Kjome
hoju at visi.com
Sun Mar 18 00:10:44 CET 2007
At 08:37 AM 3/17/2007, you wrote:
>Jake, I did some testing and have determined that logging to separate files
>works when I use Log4j.jar directly, but when I use JCL and SLF4j
>(jcl104-over-slf4j-1.3.0.jar, slf4j-api-1.3.0.jar, and
>slf4j-log4j12-1.3.0.jar),
>the log entries only write to appA.log. This is obviously a
problem because my
>real framework extends Spring, which uses JCL internally.
>
That's an interesting finding. When it worked for you, did you have
to use the WEB-INF/weblogic.xml file I suggested might be necessary
in a previous email, or did it work without that? BTW, where do you
put commons-logging.jar and slf4j jars? Are they in the server
classpath as well alongside log4j.jar? Actually, I can't see how it
couldn't be. If your framework extends Spring, Spring jars and their
dependencies would also have to be on the server classpath. Given
this, I hope all the libraries use non-static loggers.
>Here's what I did:
>Created 3 new Eclipse projects: myframework, appA, and appB.
>-myframework contains only one servlet: com.myframework.web.HelloServlet.
>-myframework.jar is deployed on weblogic's classpath, along with log4j.jar
>-appA and appB are identical, except appA's log4j_webapp.properties
file sets:
>log4j.logger.com.myframework=debug
>and appB's file sets:
>log4j.logger.com.myframework=warn.
>-appA and appB both have the JNDI log4j env-entries and the
>"log4j/context-name"
>is set to appA for appA, appB for appB.
>
>Weblogic starts with -Dlog4j.repositorySelector=JNDI
>
>When I configure HelloServlet to use Log4j directly logging works fine:
>package com.myframework.web;
>import java.io.IOException;
>import java.io.PrintWriter;
>
>import javax.servlet.ServletException;
>import javax.servlet.http.HttpServlet;
>import javax.servlet.http.HttpServletRequest;
>import javax.servlet.http.HttpServletResponse;
>
>import org.apache.log4j.Logger;
>
>public class HelloServlet extends HttpServlet {
> private Logger logger = Logger.getLogger(getClass());
> protected void doGet(HttpServletRequest request,
HttpServletResponse response)
>throws ServletException, IOException {
> logger.debug("entering doGet()");
> logger.info("info 1");
> logger.warn("warn 1");
> logger.debug("leaving doGet()");
> PrintWriter out = response.getWriter();
> out.println("Hello World");
> }
>}
>
>When I configure HelloServlet to use JCL over SLF4j - it only writes
>to appA.log
>for both apps:
>package com.myframework.web;
>import java.io.IOException;
>import java.io.PrintWriter;
>
>import javax.servlet.ServletException;
>import javax.servlet.http.HttpServlet;
>import javax.servlet.http.HttpServletRequest;
>import javax.servlet.http.HttpServletResponse;
>
>import org.apache.commons.logging.Log;
>import org.apache.commons.logging.LogFactory;
>
>public class HelloServlet extends HttpServlet {
> private Log logger = LogFactory.getLog(getClass());
> protected void doGet(HttpServletRequest request,
HttpServletResponse response)
>throws ServletException, IOException {
> logger.debug("entering doGet()");
> logger.info("info 1");
> logger.warn("warn 1");
> logger.debug("leaving doGet()");
> PrintWriter out = response.getWriter();
> out.println("Hello World");
> }
>}
>
>I'm going to look through SLF4j's implementation of the JCL interfaces
>to see if
>I can just change the JCL interfaces to use Log4j directly... do you think
>that's correct?
>
This is getting out of my area of expertise. I'm a Log4j developer,
not an SLF4J developer. Ceki may have some ideas here. I find it
odd that wrappers would have an effect whatsoever. If all they are
doing is forwarding to Log4j then, ultimately, Log4j should be
controlling which logger repository is used.
BTW, do you have a default config file (log4j.properties or
log4j.xml) in the server's classpath that Log4j uses to configure its
default logger repository? If so, does it point to the same Log file
as appA? If it does, then that could be the culprit. Wrapped
loggers might be logging to the default logger
repository. Otherwise, I find it odd that the repository selector
would be arbitrarily (but consistently) choosing a non-default logger
repository to log to.
>Thanks again
No problem. I'd like to see this issue cleared up almost as much as you.
Jake
>
>_______________________________________________
>user mailing list
>user at slf4j.org
>http://www.slf4j.org/mailman/listinfo/user
More information about the slf4j-user
mailing list