You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by nashrul <an...@yahoo.com> on 2008/05/22 11:32:46 UTC

Error using log4j in Tomcat 5.5

Hi all, I'm a beginner to web application
I tried to create a simple web application, namely WebTest. It only contains
one servlet, like this:

    quote:
    package solmit;

    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 WebTest extends HttpServlet {
    private static Logger log = Logger.getLogger(WebTest.class);

    public void doGet(HttpServletRequest request, HttpServletResponse
response)
    throws IOException, ServletException
    {
    log.debug("anas: about to enter doGet");
    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();

    writer.println("<html><head><title>Simple Web
Application</title></head>");
    writer.println("<body><h1>A Simple Web Application</h1>");
    writer.println("Here's some text...<br>...and a bit more text");
    writer.println("</body></html>");
    log.debug("anas: about to leave doGet");
    }
    }

My web.xml file looks like this:
     
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    	<display-name>WebTest</display-name>
    	<welcome-file-list>
    		<welcome-file>index.html</welcome-file>
    		<welcome-file>index.htm</welcome-file>
    		<welcome-file>index.jsp</welcome-file>
    		<welcome-file>default.html</welcome-file>
    		<welcome-file>default.htm</welcome-file>
    		<welcome-file>default.jsp</welcome-file>
    	</welcome-file-list>
    	<servlet>
    		<servlet-name>some dummy name</servlet-name>
    		<servlet-class>solmit.WebTest</servlet-class>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>some dummy name</servlet-name>
    		<url-pattern>/start-web-test</url-pattern>
    	</servlet-mapping>
    </web-app>
     
I also created log4j.properties file in <web-app>/WEB-INF/classes directory.
It contains the following code:
        
    log4j.logger.solmit=ALL, A
    log4j.logger.org.apache=OFF, A
     
    log4j.appender.A=org.apache.log4j.ConsoleAppender
    log4j.appender.A.layout=org.apache.log4j.PatternLayout
     log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n 


I packaged this application into WebTest.war.
When I dropped this package into my Tomcat (Tomcat 5.5), and tried to access
web app using this url :http://localhost:8080/WebTest/start-web-test
I got error messages on my stderr_20080522 log:

        
    log4j:WARN No appenders could be found for logger
(org.apache.catalina.startup.Embedded).
    log4j:WARN Please initialize the log4j system properly.


Oh, I've also dropped log4j-1.2.13.jar and commons-logging-1.0.4.jar on
Tomcat/common/lib
I've read tomcat documentation on logging.. but it seems that it doesn't
give me some clue to use log4j logging in my application
("http://localhost:8080/tomcat-docs/logging.html")
I've also already read the documentation about log4j on
"http://www.laliluna.de/log4j-tutorial.html"

What the error actually means. ??
How do we setup tomcat to use log4j for logging ??
Any help would be greatly appreciated..
Thanks

My computer spec:
Tomcat 5.5
Jre 1.5.0_15
Windows XP Prof edition

-- 
View this message in context: http://www.nabble.com/Error-using-log4j-in-Tomcat-5.5-tp17400689p17400689.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Error using log4j in Tomcat 5.5

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nashrul,

nashrul wrote:
| my log4j logging works now, it prints the logs to stdout_20080523.log....
| Actually, I followed the instruction on log4j docs..
| I created initialization servlet, Log4jInit.class, that initializes log4j
| and loaded on startup...
| This initialization class looks like this:
|
| 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);
|     }
|   }


I would do "new PropertyConfigurator()" if there is no log4j-init-file
set in the init-params, because it will pick-up log4j.properties from
the classpath. Then you get a reasonable default configuration without
having to add more stuff to your web.xml.

Just my two cents.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkg2zq4ACgkQ9CaO5/Lv0PDU+ACgqZ5Ejr2KG40+Mm/iBHjGO6cd
EwkAoMFrEznVF/Mt4A9CmegdxwD5xDfd
=+oH1
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Error using log4j in Tomcat 5.5

Posted by nashrul <an...@yahoo.com>.
Thanks a lot Schultz, 
my log4j logging works now, it prints the logs to stdout_20080523.log....
Actually, I followed the instruction on log4j docs..
I created initialization servlet, Log4jInit.class, that initializes log4j
and loaded on startup...
This initialization class looks like this:

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) {
  }
}
 and adding this entry to web.xml file:

<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.properties</param-value>
    </init-param>

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

In the class above, the static method configure(java.util.Properties
properties) of PropertyConfigurator class is called to initialize log4j
while you suggest to instantiate this object..
Well, another question I'd like to ask:
What is the difference  between configuring log4j by calling this static
method (configure(java.util.Properties properties)) as written above and
instantiating PropertyConfigurator class and call its doConfigure() method
??



Christopher Schultz-2 wrote:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Nashrul,
> 
> nashrul wrote:
> | Hi all, I'm a beginner to web application [and log4j isn't working for
> me].
> 
> [snip]
> 
> | I also created log4j.properties file in <web-app>/WEB-INF/classes
> directory.
> | It contains the following [configuration]:
> |
> |     log4j.logger.solmit=ALL, A
> |     log4j.logger.org.apache=OFF, A
> |
> |     log4j.appender.A=org.apache.log4j.ConsoleAppender
> |     log4j.appender.A.layout=org.apache.log4j.PatternLayout
> |     log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
> |
> |
> | I packaged this application into WebTest.war.
> | When I dropped this package into my Tomcat (Tomcat 5.5), and tried to
> access
> | web app using this url :http://localhost:8080/WebTest/start-web-test
> | I got error messages on my stderr_20080522 log:
> |
> |     log4j:WARN No appenders could be found for logger
> | (org.apache.catalina.startup.Embedded).
> |     log4j:WARN Please initialize the log4j system properly.
> 
> This means that log4j was asked to log a message before the logging
> system was initialized. IIRC, log4j is supposed to automatically
> configure itself on first-use by looking for log4j.properties in the
> classpath, but that does not appear to be happening, here.
> 
> I recall having the same problem on several of our projects, and we
> simply added this to our initialization listener:
> 
> ~   new org.apache.log4j.PropertyConfigurator();
> 
> This forces log4j to initialize itself using a properties file, and it
> will search the classpath for it -- so placing your log4j.properties
> file in WEB-INF/classes is appropriate.
> 
> | Oh, I've also dropped log4j-1.2.13.jar and commons-logging-1.0.4.jar on
> | Tomcat/common/lib
> 
> Do not do that. Remove those files from common/lib and anywhere else you
> tried putting them. Just use WEB-INF/lib in your own application for
> log4j.jar and commons-logging (if you actually need commons-logging).
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iEYEARECAAYFAkg1dj8ACgkQ9CaO5/Lv0PDbqgCgouMNS+GuLE/a2qsP/u5/sCV8
> 494AnRMbIfdxLyY8MZoQz8p3r2Yufy7u
> =kSFm
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Error-using-log4j-in-Tomcat-5.5-tp17400689p17420689.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Error using log4j in Tomcat 5.5

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nashrul,

nashrul wrote:
| Hi all, I'm a beginner to web application [and log4j isn't working for
me].

[snip]

| I also created log4j.properties file in <web-app>/WEB-INF/classes
directory.
| It contains the following [configuration]:
|
|     log4j.logger.solmit=ALL, A
|     log4j.logger.org.apache=OFF, A
|
|     log4j.appender.A=org.apache.log4j.ConsoleAppender
|     log4j.appender.A.layout=org.apache.log4j.PatternLayout
|     log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
|
|
| I packaged this application into WebTest.war.
| When I dropped this package into my Tomcat (Tomcat 5.5), and tried to
access
| web app using this url :http://localhost:8080/WebTest/start-web-test
| I got error messages on my stderr_20080522 log:
|
|     log4j:WARN No appenders could be found for logger
| (org.apache.catalina.startup.Embedded).
|     log4j:WARN Please initialize the log4j system properly.

This means that log4j was asked to log a message before the logging
system was initialized. IIRC, log4j is supposed to automatically
configure itself on first-use by looking for log4j.properties in the
classpath, but that does not appear to be happening, here.

I recall having the same problem on several of our projects, and we
simply added this to our initialization listener:

~   new org.apache.log4j.PropertyConfigurator();

This forces log4j to initialize itself using a properties file, and it
will search the classpath for it -- so placing your log4j.properties
file in WEB-INF/classes is appropriate.

| Oh, I've also dropped log4j-1.2.13.jar and commons-logging-1.0.4.jar on
| Tomcat/common/lib

Do not do that. Remove those files from common/lib and anywhere else you
tried putting them. Just use WEB-INF/lib in your own application for
log4j.jar and commons-logging (if you actually need commons-logging).

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkg1dj8ACgkQ9CaO5/Lv0PDbqgCgouMNS+GuLE/a2qsP/u5/sCV8
494AnRMbIfdxLyY8MZoQz8p3r2Yufy7u
=kSFm
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Please review this worker timeout configuration

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stephanie,

Please start a new thread when posting a new question.

Stephanie Wullbieter wrote:
| Please have a look at this reference worker timeouts:
|
| worker.vorlagedummy.port=8009
| worker.vorlagedummy.type=ajp13
| worker.vorlagedummy.sticky_session=True
| worker.vorlagedummy.socket_keepalive=True
| worker.vorlagedummy.connect_timeout=50000
| worker.vorlagedummy.prepost_timeout=50000
| worker.vorlagedummy.connection_pool_timeout=30
|
| We switch from mod_jk 1.2.5 to 1.2.23
| And with 1.2.5 we had a socket_timeout (now named
| connection_pool_timeout) of 30s and the other timouts are new. So first
| I want to set high timeouts because our network is unstable with
| sometimes big latency (e.g. 20s) because the firewall is sometimes
| overloaded.

Wow -- time to get a new firewall.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkg1dnkACgkQ9CaO5/Lv0PBBRwCgmJX6zFz+oFhj2zjJ9IFX3Dsl
m0AAoMHKxKGXUGPVV9uIbaYvTcQ5FKLD
=nZV2
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Please review this worker timeout configuration

Posted by Rainer Jung <ra...@kippdata.de>.
Stephanie Wullbieter schrieb:
> Please have a look at this reference worker timeouts:
> 
> worker.vorlagedummy.port=8009
> worker.vorlagedummy.type=ajp13
> worker.vorlagedummy.sticky_session=True
> worker.vorlagedummy.socket_keepalive=True
> worker.vorlagedummy.connect_timeout=50000
> worker.vorlagedummy.prepost_timeout=50000

50 seconds is pretty long for a connect and a prepost timeout.
As you say, your network is unstable. If you want mod_jk to wait for 
such a long time to finally succeed, 50 seconds will be OK, but this 
will mean, that under high load a lot of requests might wait and block 
httpd ressources. If you prefer mod_jk to throw and error and clear the 
system whenever a long network latency shows up, reduce those two 
timeouts to something like 10 seconds.

> worker.vorlagedummy.connection_pool_timeout=30

This is pretty short. The timeout determines, how long we keep an idle 
backend connection open for reuse. Usually it is more in the range of 
300 seconds. You should also adjust connectionTimeout on the Tomcat AJP 
connector to the same value multiplied by 1000 (it is in milliseconds on 
the Tomcat side).

Some more info on the timepouts is contained in

http://tomcat.apache.org/connectors-doc/generic_howto/timeouts.html

> We switch from mod_jk 1.2.5 to 1.2.23

If you are doing the upgrade now (which is good), I would suggest to go 
directly to 1.2.26.

> And with 1.2.5 we had a socket_timeout (now named connection_pool_timeout) of 30s and the other timouts are new. So first I want to set high timeouts because our network is unstable with sometimes big latency (e.g. 20s) because the firewall is sometimes overloaded.

No, there still is a socket_timeout. It is *not* the same as the 
connection_pool_timeout.

> Is this ok ?

See above :)

Regards,

Rainer

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Please review this worker timeout configuration

Posted by Stephanie Wullbieter <sw...@gmx.de>.
Please have a look at this reference worker timeouts:

worker.vorlagedummy.port=8009
worker.vorlagedummy.type=ajp13
worker.vorlagedummy.sticky_session=True
worker.vorlagedummy.socket_keepalive=True
worker.vorlagedummy.connect_timeout=50000
worker.vorlagedummy.prepost_timeout=50000
worker.vorlagedummy.connection_pool_timeout=30

We switch from mod_jk 1.2.5 to 1.2.23
And with 1.2.5 we had a socket_timeout (now named connection_pool_timeout) of 30s and the other timouts are new. So first I want to set high timeouts because our network is unstable with sometimes big latency (e.g. 20s) because the firewall is sometimes overloaded.

Is this ok ?
-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org