You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Andrea Fabris <an...@email.it> on 2003/05/13 14:49:51 UTC

strange log4j behaviour

Hi!
I wrote a servlet using log4j-1.2.8 for logging purposes.
No i had to duplicate this servlet under the same servlet engine (tomcat
3.3.1a), so i copied the servlet directory under webapps dir using another
name. In this manner i have two context doing the same job (one for test and
one for production.. well it's not a good idea but right now we haven't a
lot of machines).
The tow contexts use different configurations (they have differente values
in the web.xml): for logging they use a file under the <context-dir>/WEB-INF
directory.
Now the problem is that when i start tomcat and i run the servlet, the log
lines are written in the log files of the servlet that was last initialized.
I don't know if it is caused by the fact that the two servlets use the same
name for the logger class (Logger.getLogger(<name>)), or if it's some log4j
bug...

I use:
JDK 1.3.1_07-b02
Tomcat 3.3.1a
log4j 1.2.8 (installed under lib/apps)

Someone can help me?

Regards
Andrea Fabris




--
Email.it, the professional e-mail, gratis per te: http://www.email.it/f

Sponsor:
Vieni a visitare il Garden Center Peraga. Seimila metri quadrati di esposizione per servire una clientela competente ed esigente.
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=1480&d=13-5

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


Re: strange log4j behaviour

Posted by Andrea Fabris <an...@email.it>.
Thank you very much for your help, Jacob.
It was very useful

Regards
Andrea Fabris




--
Email.it, the professional e-mail, gratis per te: http://www.email.it/f

Sponsor:
Prova la Pasta di Gragnano, la prima al mondo: gustosa e massimo rendimento.
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=984&d=15-5

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


Re: strange log4j behaviour

Posted by Jacob Kjome <ho...@visi.com>.
Hi Andrea,

This is to be expected based on the fact that you have your log4j.jar in a 
common classloader and you aren't using a custom repository selector.  The 
way that logging is separated in a common environment is via separate 
logger repositories.  You can read about that here:
http://www.qos.ch/logging/sc.html

looks like this will also provide some info as well:
http://www.onjava.com/pub/a/onjava/2003/04/02/log4j_ejb.html

The solution is one of two things...

1.  Put log4j.jar in the WEB-INF/lib directory of each webapp and, in 
Tomcat-3.3.x's case, don't put it in lib/apps because Tomcat-3.3.x will 
load jars from lib/apps before WEB-INF/lib.  Kind of odd behavior if you 
ask me, but that is my understanding of how Tomcat-3.3.x works.  For 
Tomcat-4.x.x you won't have to worry about having log4j.jar also in 
shared/lib or common/lib because jars will be loaded from WEB-INF/lib first 
without exception.

2.  Use a custom repository selector.  In this case, you can have log4j in 
lib/apps in Tomcat-3.3 or common/lib in Tomcat-4.x.x and not have to put 
log4j.jar in each webapp's WEB-INF/lib and get proper logging 
separation.  You won't need to write this yourself.  I wrote it for 
you.  Check out the log4j-sandbox project where I have written a log4j 
servlet initializer (for servers supporting servlet 2.2) and a log4j 
servlet context listener initializer (for servers supporting servlet 
2.3+).  These initializers set up log4j and install custom repository 
selectors to enable separate logger repositories.  The documentation is all 
in the javadoc of the servlet context listener.  See:

http://cvs.apache.org/viewcvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/selector/
InitServlet.java
InitContextListener.java

http://cvs.apache.org/viewcvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/servlet/
ContextClassLoaderSelector.java
ContextJNDISelector.java

To use these, grab the latest CVS of log4j-sandbox and run "ant jar"

That will build a few jars.  The ones you are interested in are:
log4j-sandbox-servlet-0.1alpha.jar
log4j-sandbox-selector-0.1alpha.jar

Put log4j-sandbox-selector-0.1alpha.jar in the lib/apps directory next to 
log4j.jar.
Put log4j-sandbox-servlet-0.1alpha.jar in each webapp's WEB-INF/lib directory.

Make sure to read the javadoc on how to configure everything.  Make sure 
that under Tomcat-3.x.x, then InitServlet gets loaded on startup before all 
other servlets.  If you upgrade to Tomcat-4.x.x, the InitContextListener 
will load before all filters and servlets, so you won't have to worry about 
order of startup.

Reply back if you have troubles in getting this running.

Jake


At 02:59 PM 5/13/2003 +0200, you wrote:
>Andrea,
>
>This is not a dev question. Please forward your question to log4j-user 
>mailing list where it will be answered.
>
>At 02:49 PM 5/13/2003 +0200, you wrote:
>>Hi!
>>I wrote a servlet using log4j-1.2.8 for logging purposes.
>>No i had to duplicate this servlet under the same servlet engine (tomcat
>>3.3.1a), so i copied the servlet directory under webapps dir using another
>>name. In this manner i have two context doing the same job (one for test and
>>one for production.. well it's not a good idea but right now we haven't a
>>lot of machines).
>>The tow contexts use different configurations (they have differente values
>>in the web.xml): for logging they use a file under the <context-dir>/WEB-INF
>>directory.
>>Now the problem is that when i start tomcat and i run the servlet, the log
>>lines are written in the log files of the servlet that was last initialized.
>>I don't know if it is caused by the fact that the two servlets use the same
>>name for the logger class (Logger.getLogger(<name>)), or if it's some log4j
>>bug...
>>
>>I use:
>>JDK 1.3.1_07-b02
>>Tomcat 3.3.1a
>>log4j 1.2.8 (installed under lib/apps)
>>
>>Someone can help me?
>>
>>Regards
>>Andrea Fabris
>
>--
>Ceki  For log4j documentation consider "The complete log4j manual"
>       http://www.qos.ch/shop/products/clm_t.jsp
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org

Re: strange log4j behaviour

Posted by Ceki Gülcü <ce...@qos.ch>.
Andrea,

This is not a dev question. Please forward your question to log4j-user 
mailing list where it will be answered.

At 02:49 PM 5/13/2003 +0200, you wrote:
>Hi!
>I wrote a servlet using log4j-1.2.8 for logging purposes.
>No i had to duplicate this servlet under the same servlet engine (tomcat
>3.3.1a), so i copied the servlet directory under webapps dir using another
>name. In this manner i have two context doing the same job (one for test and
>one for production.. well it's not a good idea but right now we haven't a
>lot of machines).
>The tow contexts use different configurations (they have differente values
>in the web.xml): for logging they use a file under the <context-dir>/WEB-INF
>directory.
>Now the problem is that when i start tomcat and i run the servlet, the log
>lines are written in the log files of the servlet that was last initialized.
>I don't know if it is caused by the fact that the two servlets use the same
>name for the logger class (Logger.getLogger(<name>)), or if it's some log4j
>bug...
>
>I use:
>JDK 1.3.1_07-b02
>Tomcat 3.3.1a
>log4j 1.2.8 (installed under lib/apps)
>
>Someone can help me?
>
>Regards
>Andrea Fabris

--
Ceki  For log4j documentation consider "The complete log4j manual"
       http://www.qos.ch/shop/products/clm_t.jsp 


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