View | Details | Raw Unified | Return to bug 32249
Collapse All | Expand All

(-)logging.xml (-35 / +80 lines)
Lines 14-69 Link Here
14
<body>
14
<body>
15
15
16
  <section name="Introduction">
16
  <section name="Introduction">
17
	<p>
18
		Tomcat 5.5 uses Commons Logging throughout its internal code allowing the 
19
		developer to choose a logging configuration that suits their needs, e.g
20
		JDK Logging or log4j. Commons Logging provides Tomcat the ability to log
21
		hierarchially across various log levels without needing to rely on a particular
22
		logging implementation. Commons Logging is therefore a bridge to other implementations.
23
		<a href="http://jakarta.apache.org/commons/logging/">Visit the Commons Logging project</a>
24
		for more information.
25
	</p>
26
	<p>
27
		An important consequence for Tomcat 5.5 is that the &lt;Logger&gt; element found in 
28
		previous versions to create a localhost_log, is no longer a valid nested element 
29
		of &lt;Context&gt;. Instead, stdout will collect runtime exceptions and other uncaught
30
		exception generated by web applications. If the developer wishes to collect detailed internal 
31
		Tomcat logging (i.e what is happening within the Tomcat engine), then they should configure 
32
		a logging system such as JDK Logging or log4j as detailed next.
33
	</p>
34
	<p>
35
		One note to point out is that currently, the log4j configuration will not function on
36
		Tomcat server startup, so JDK Logging is more reliable at this point. This is a known
37
		issue in the pipeline for fix.
38
	</p>
17
  </section>
39
  </section>
18
40
19
  <section name="java.util.logging">
41
  <section name="java.util.logging">
42
	<p>
43
		In order to configure JDK logging you should have JDK 1.4+. Tomcat 5.5 is intended for
44
		JDK 5.0, but can be run on JDK 1.4 using a compatibility package.
45
	</p>
46
	<p>
47
		In order to configure JDK Logging, you should find the JDK's logging.properties file. Check
48
		your JAVA_HOME environment setting to see which JDK Tomcat is using (or maybe JRE 5.0 as Tomcat
49
		can now run on a JRE from version 5.5). The file will be in <i>${JAVA_HOME}/jre/lib</i>.
50
	</p>
51
	<p>
52
		The default logging.properties specifies a ConsoleHandler for routing logging to stdout and
53
		also a FileHandler. A handler's log level threshold can be set using SEVERE, CONFIG, INFO, 
54
		WARN, FINE, FINEST or ALL. The logging.properties shipped with JDK is set to INFO. You
55
		can also target specific packages to collect logging from and specify a level. Here is how
56
		you would set debugging from Tomcat. You would need to ensure the ConsoleHandler's level is also
57
		set to collect this threshold, so FINEST or ALL should be set.
58
	</p>
59
	<p><source>org.apache.catalina.level=FINEST</source></p>
60
	<p>A limitation of JDK Logging appears to be the inability to have per-web application logging, 
61
		as the configuration is per-VM. It is advisable to use log4j for per-web application logging
62
		as elabatorated on below.
63
	</p>
20
  </section>
64
  </section>
21
65
22
  <section name="log4j">
66
  <section name="log4j">
23
    <p>
67
    <p>
24
      	Tomcat 5.5 has done away with localhost_log which you may be familiar with
68
      As mentioned, an known issue prevents this log4j configuration working propertly on Tomcat startup,
25
	  	as the runtime exception/stack trace log. These types of error are usually thrown
69
	  but is known to work when combined with some actions, such as deployment of a WAR. It is
26
	  	by uncaught exceptions, but are still valuable to the developer. They can now be
70
	  provided for completeness.
27
	  	found in the stdout log.
28
	</p>
29
30
	<p>
31
		If you need to setup cross-context detailed logging from within Tomcat's code, then you can use a simple
32
		log4j configuration. Note that this logging van be very verbose depending on the log level you chose to use.
33
		Note also that a log4j logging configuration is not going to produce stack trace type logging, that is output to
34
		stdout as discussed.
35
	</p>
71
	</p>
36
72
37
	<p>Follow the following steps to setup a file named tomcat.log that has internal Tomcat logging output to it.</p>
38
39
	<ol>
73
	<ol>
40
		<li>
74
		<li>
41
			Create a file called log4j.properties with the following content and save it into common/classes. 
75
			Create a file called log4j.properties with the following content and save it into common/classes. 
42
			Use the appropriate file path convention for your OS, here is is Windows, and example *nix path may be
76
			Use the appropriate file path convention for your OS, here is is Windows, and example *nix path may be
43
			/var/jakarta-tomcat-5.5.4/logs/tomcat.log
77
			/var/jakarta-tomcat-5.5.4/logs/tomcat.log
44
<source>
78
			<source>
45
log4j.rootLogger=debug, R
79
			log4j.rootLogger=debug, R
46
log4j.appender.R=org.apache.log4j.RollingFileAppender
80
			log4j.appender.R=org.apache.log4j.RollingFileAppender
47
log4j.appender.R.File=d:/jakarta-tomcat-5.5.4/logs/tomcat.log
81
			log4j.appender.R.File=d:/jakarta-tomcat-5.5.4/logs/tomcat.log
48
log4j.appender.R.MaxFileSize=10MB
82
			log4j.appender.R.MaxFileSize=500KB
49
log4j.appender.R.MaxBackupIndex=10
83
			log4j.appender.R.MaxBackupIndex=10
50
log4j.appender.R.layout=org.apache.log4j.PatternLayout
84
			log4j.appender.R.layout=org.apache.log4j.PatternLayout
51
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
85
			log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
52
log4j.logger.org.apache.catalina=DEBUG, R</source>
86
			log4j.logger.org.apache.catalina=DEBUG, R</source>
53
		</li>
87
		</li>
54
		<li><a>Acquire log4j1.2.8.jar</a> and add it into Tomcat's common/lib folder.</li>
88
		<li>Acquire log4j1.2.8.jar and add it into Tomcat's common/lib folder.</li>
55
		<li>Start Tomcat</li>
89
		<li>Start Tomcat</li>
56
	</ol>
90
	</ol>
57
91
58
	<p>
92
	<p>
59
		This log4j configuration sets up a file called tomcat.log in your Tomcat logs folder with a maximum file size of 10MB and
93
		This log4j configuration will set up a file called tomcat.log in your Tomcat logs folder with 
60
		up to 10 backups. DEBUG level is specified which will result in the most verbose output from Tomcat. The above generated
94
		a maximum file size of 500KB and up to 10 backups. DEBUG level is specified which will result 
61
		about 5MB of logging with bundled web applications and Struts web applications.
95
		in the most verbose output from Tomcat. The above can generate in excess of 5MB of logging with 
96
		bundled web applications and Struts web applications.
62
	</p>
97
	</p>
63
	
98
	
64
	<p>
99
	<p>
65
		You can of course choose to be more picky about which packages to include in the logging. For example try substituting the
100
		You can of course choose to be more picky about which packages to include in the logging as with
66
		last line of the above configuration with one of these:
101
		the JDK Logging. For example try substituting the last line of the above configuration with one 
102
		of these:
67
	
103
	
68
		<ul>
104
		<ul>
69
			<li>log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=DEBUG, R</li>
105
			<li>log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=DEBUG, R</li>
Lines 72-85 Link Here
72
		</ul>
108
		</ul>
73
	</p>
109
	</p>
74
	
110
	
75
	<p>The usefulness of what you will find from the log4j logging is debatable and will depend on your needs. Your
76
		web applications should certainly use their own log4j configuration. This is valid <i>with</i> the above.
77
		You would place a similar log4j.properties file in your web application's WEB-INF/classes folder, and log4j1.2.8.jar into
78
		WEB-INF/lib. Then specify your package level logging. This is a basic setup of log4j and you should consult the log4j
79
		documentation for more options, but hopefully this section will get you up to a basic speed.
80
	</p>
81
	
82
  </section>
111
  </section>
112
  
113
  <section name="Conclusion">
114
	<p>
115
		The usefulness of what you will find from internal Tomcat logging is debatable for web 
116
		applications. Unless a problem with Tomcat itself exists, it is probably not required. 
117
	</p>
118
	<p>
119
		It is much more common and recommended for web application themselves to be configured with
120
		a logging setup. In the case of JDK Logging, you could setup package loggers to collect logging
121
		from your own applications, e.g <code>com.mycomp.myapp.level=DEBUG</code>. In the case of log4j, a custom
122
		log4j.properties file would be placed into your web application's WEB-INF/classes folder and 
123
		log4j-1.2.8.jar into WEB-INF/lib and the log4j.properties file would setup a set of 
124
		(normally) file appenders to collect the logging, again with package level setup, e.g
125
		<code>log4j.logger.org.mycomp.myapp=DEBUG, APPENDER_TO_USE</code>.
126
	</p>
127
  </section>	
83
128
84
</body>
129
</body>
85
</document>
130
</document>

Return to bug 32249