You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Sathiskumar Govindasamy <gs...@yahoo.com> on 2002/04/02 03:28:13 UTC

Log4J and Tomcat 4 - Newbie

  Hello,

I am very new to both Tomcat4 and Log4J. I have been using apache-jserv 
for a very long time and finally decided to jump into Tomcat. I found 
tomcat doing the System.err logging to catalina.out file in 
/vat/tomcat4/logs directory. I would like to leave whatever tomcat4 does 
as it is. In addition to that I would like to use Log4J to log debug, 
info, warning messages that are specific to different context. I have 
gone through this mailing list's archeive and couldn't find any 
reference to similar question. So, I am posting it.

Here is what I have done

in /etc/tomcat4/conf/tomcat4.conf file I added this

export CATALINA_OPTS="-Dlog4j.configuration=log4j.properties"

I have placed the log4j-core.jar, parser.jar, jaxp.jar files in 
/var/tomcat4/webapps/myapp/WEB-INF/lib/ directory

I have the file log4j.properties in 
/var/tomcat4/webapps/myapp/WEB-INF/classes/ directory. Follwing is the 
content of that file

log4j.rootCategory=DEBUG, A1
log4j.appender.A1=org.apache.log4j.FileAppender
log4j.appender.A1.File={CATALINA_HOME}/logs/myapp.log
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] (%x) - %m\n

In my servlet I have the follwoing lines

import org.apache.log4j.*;
....
...

                        
PropertyConfigurator.configure("/var/tomcat4/webapps/eis/WEB-INF/classes/log4j.properties");
                        
PropertyConfigurator.configureAndWatch("/var/tomcat4/webapps/eis/WEB-INF/classes/log4j.properties");



                         // Initialize a logging category.  Here, we get 
THE ROOT CATEGORY
                        //static Category cat = Category.getRoot();
                        // Or, get a custom category

                        cat = Category.getRoot();
                        cat.setPriority(Priority.DEBUG);

                        // From here on, log away!  Methods are: 
cat.debug(your_message_string),
                        // cat.info(...), cat.warn(...), cat.error(...), 
cat.fatal(...)
                        cat.debug("Testing the logger DEBUG");
                        cat.info("Testing the logger INFO");
                        cat.warn("Testing the logger WARN");
                        cat.error("Testing the logger ERROR");
                        cat.fatal("Testing the logger FATAL");

   


I am basically using tomcat4 as servlet container. myapp is my context. 
The servlet part of it working just fine. I does rest of the things that 
I have, except the log4j part. I have the tomcat4 threads that looks 
like this

tomcat4  30939 30938  0 16:26 ?        00:00:02 
/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties 
-Djava.endorsed.dirs= -cl
tomcat4  30940 30938  0 16:26 ?        00:00:00 
/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties 
-Djava.endorsed.dirs= -cl
tomcat4  30941 30938  0 16:26 ?        00:00:00 
/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties 
-Djava.endorsed.dirs= -cl
tomcat4  30942 30938  0 16:26 ?        00:00:00 
/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties 
-Djava.endorsed.dirs= -cl
tomcat4  30943 30938  0 16:26 ?        00:00:00 
/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties 
-Djava.endorsed.dirs= -cl
tomcat4  30944 30938  0 16:26 ?        00:00:00 
/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties 
-Djava.endorsed.dirs= -cl
tomcat4  30945 30938  0 16:26 ?        00:00:04 
/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties 
-Djava.endorsed.dirs= -cl
tomcat4  30948 30938  0 16:26 ?        00:00:00 
/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties 
-Djava.endorsed.dirs= -cl
tomcat4  30949 30938  0 16:26 ?        00:00:00 
/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties 
-Djava.endorsed.dirs= -cl

I would greatly appreciate if you folks can help me out in configuring 
this correctly. I wish the log4j documentation had more information on 
installation of configuration with tomcat.

Thanks
Sathis


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Log4J and Tomcat 4 - Newbie

Posted by Sathiskumar Govindasamy <gs...@yahoo.com>.
Hi Ray,

Thanks for your suggestion. It worked.

Sathis

Ray Thomas wrote:

>This is anecdotal info so I thought I'd better reply off the mailing
>list... anyway...
>
>If you are using the default log4j.properties configuration file, you
>shouldn't need to specify the -D option when starting tomcat.  Try
>removing that and the PropertyConfigurator calls, and letting log4j find
>the "default" config file automatically where you have it located in
>WEB-INF\classes\log4j.properties.  Also, all the code you should need is
>the import, and Logger.getRootLogger().  This worked w/o troubles for
>me.
>
>-R
>----- Original Message -----
>From: "Sathiskumar Govindasamy" <gs...@yahoo.com>
>To: <lo...@jakarta.apache.org>
>Sent: Monday, April 01, 2002 6:28 PM
>Subject: Log4J and Tomcat 4 - Newbie
>
>
>>  Hello,
>>
>>I am very new to both Tomcat4 and Log4J. I have been using
>>
>apache-jserv
>
>>for a very long time and finally decided to jump into Tomcat. I found
>>tomcat doing the System.err logging to catalina.out file in
>>/vat/tomcat4/logs directory. I would like to leave whatever tomcat4
>>
>does
>
>>as it is. In addition to that I would like to use Log4J to log debug,
>>info, warning messages that are specific to different context. I have
>>gone through this mailing list's archeive and couldn't find any
>>reference to similar question. So, I am posting it.
>>
>>Here is what I have done
>>
>>in /etc/tomcat4/conf/tomcat4.conf file I added this
>>
>>export CATALINA_OPTS="-Dlog4j.configuration=log4j.properties"
>>
>>I have placed the log4j-core.jar, parser.jar, jaxp.jar files in
>>/var/tomcat4/webapps/myapp/WEB-INF/lib/ directory
>>
>>I have the file log4j.properties in
>>/var/tomcat4/webapps/myapp/WEB-INF/classes/ directory. Follwing is the
>>content of that file
>>
>>log4j.rootCategory=DEBUG, A1
>>log4j.appender.A1=org.apache.log4j.FileAppender
>>log4j.appender.A1.File={CATALINA_HOME}/logs/myapp.log
>>log4j.appender.A1.layout=org.apache.log4j.PatternLayout
>>log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] (%x) - %m\n
>>
>>In my servlet I have the follwoing lines
>>
>>import org.apache.log4j.*;
>>....
>>...
>>
>>
>>
>PropertyConfigurator.configure("/var/tomcat4/webapps/eis/WEB-INF/classes
>/log4j.properties");
>
>>
>PropertyConfigurator.configureAndWatch("/var/tomcat4/webapps/eis/WEB-INF
>/classes/log4j.properties");
>
>>
>>
>>                         // Initialize a logging category.  Here, we
>>
>get
>
>>THE ROOT CATEGORY
>>                        //static Category cat = Category.getRoot();
>>                        // Or, get a custom category
>>
>>                        cat = Category.getRoot();
>>                        cat.setPriority(Priority.DEBUG);
>>
>>                        // From here on, log away!  Methods are:
>>cat.debug(your_message_string),
>>                        // cat.info(...), cat.warn(...),
>>
>cat.error(...),
>
>>cat.fatal(...)
>>                        cat.debug("Testing the logger DEBUG");
>>                        cat.info("Testing the logger INFO");
>>                        cat.warn("Testing the logger WARN");
>>                        cat.error("Testing the logger ERROR");
>>                        cat.fatal("Testing the logger FATAL");
>>
>>
>>
>>
>>I am basically using tomcat4 as servlet container. myapp is my
>>
>context.
>
>>The servlet part of it working just fine. I does rest of the things
>>
>that
>
>>I have, except the log4j part. I have the tomcat4 threads that looks
>>like this
>>
>>tomcat4  30939 30938  0 16:26 ?        00:00:02
>>/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties
>>-Djava.endorsed.dirs= -cl
>>tomcat4  30940 30938  0 16:26 ?        00:00:00
>>/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties
>>-Djava.endorsed.dirs= -cl
>>tomcat4  30941 30938  0 16:26 ?        00:00:00
>>/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties
>>-Djava.endorsed.dirs= -cl
>>tomcat4  30942 30938  0 16:26 ?        00:00:00
>>/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties
>>-Djava.endorsed.dirs= -cl
>>tomcat4  30943 30938  0 16:26 ?        00:00:00
>>/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties
>>-Djava.endorsed.dirs= -cl
>>tomcat4  30944 30938  0 16:26 ?        00:00:00
>>/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties
>>-Djava.endorsed.dirs= -cl
>>tomcat4  30945 30938  0 16:26 ?        00:00:04
>>/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties
>>-Djava.endorsed.dirs= -cl
>>tomcat4  30948 30938  0 16:26 ?        00:00:00
>>/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties
>>-Djava.endorsed.dirs= -cl
>>tomcat4  30949 30938  0 16:26 ?        00:00:00
>>/usr/java/j2sdk1.4.0/bin/java -Dlog4j.configuration=log4j.properties
>>-Djava.endorsed.dirs= -cl
>>
>>I would greatly appreciate if you folks can help me out in configuring
>>this correctly. I wish the log4j documentation had more information on
>>installation of configuration with tomcat.
>>
>>Thanks
>>Sathis
>>
>>
>>--
>>To unsubscribe, e-mail:
>>
><ma...@jakarta.apache.org>
>
>>For additional commands, e-mail:
>>
><ma...@jakarta.apache.org>
>
>>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>