开发者

Tomcat: recommandations for logging

I've read several questions here concerning Tomcat and logging but I still really don't understand the "bigger picture", hence my question:

How and where are my Webapps supposed to do their logging?

By default on my setup Tomcat 6.0.20 logs go in the following file/appender:

./apache-tomcat-6.0.20/logs/catalina.out

Am I suppose to have my webapps also log to this file/appender?

Let say my case is trivially simple and I've got just one servlet:

import ... // What do I import here in order to be able to log?

public class SOServlet extends HttpServlet {

    public void doGet(
        final HttpServletR开发者_JS百科equest request,
        final HttpServletResponse response
    ) throws IOException, ServletException {
    ... // I want to log here, what do I write?

What are the gotchas knowing that there are more than one webapp running on the same Tomcat? (apparently from reading the various questions there are many gotchas).

What about the .war, do I need to put log4j/sl4f/commons-logging/whatever in my .war?

For example I've read that, and I'm way more confused than before:

http://tomcat.apache.org/tomcat-6.0-doc/logging.html


How and where are my Webapps supposed to do their logging?

It depends. You can either make use of ServletContext#log() (which in turn is available in servlets by the inherited getServletContext() method) to log it into the same logfile as the servletcontainer itself, or to go for a separate logger/logfile with help of under each slf4j and/or logback/log4j. The common practice is to give each webapp its own logger so that you have more freedom and control in logging.

For the case you're interested, here is a Tomcat wiki with regard to the subject.

What are the gotchas knowing that there are more than one webapp running on the same Tomcat? (apparently from reading the various questions there are many gotchas).

If this is with regard to logging: you'll end up with poor overview in the logfile and less freedom and control in logging the individual webapps.

What about the .war, do I need to put log4j/sl4f/commons-logging/whatever in my .war?

Regardless of the library used: If it is specific to the webapp, put it in the WAR. If it is common to all webapps, put it in appserver's common lib. If it is specific to the appserver, put it in the appserver's lib.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜