Geoff Mottram (Geoff at minaret Dot biz).
Placed in the public domain on August, 2004 by the author.
Last Updated:january 27, 2005.
This document is provided ' as is ', without warranty of any kind, express or implied, including and not limited to the Warr Anties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the author is liable for any claim, damages or other liability, whether in an action of contract, Tort O R Otherwise, arising from, out of or in connection with this document or the use or other dealings in this document.
To save the output information to the log file, you need to configure the FileLogger in the Tomcat configuration file (Tomcat's conf directory) Server.xml, typically as follows:
<!--Global logger unless overridden at lower levels-->
<logger Classname= "Org.apache.catalina.logger.FileLogger"
prefix= "servlet." suffix= ". Log" timestamp= "true"/>
The servlet log can be turned on (configured with FileLogger) and turned off (no configuration FileLogger), but there is no way to specify the log output level (only the info and higher level log information can be output). Although the Tomcat document mentions that all of its logger support verbosity configuration items, it seems to have little effect.
If you want to configure Tomcat to capture all of the log data, output to a log file that generates one daily (for example, the date indicated in the file name). Tomcat in FileLogger provides a standard way to capture the servlet log stream and generate a new file every day. You can back up, delete, analyze, or other actions you want for the log files.
If Tomcat had another Catalina logger using the Commons logging interface, it would give you better control over the format of the output, although the module is fairly easy to implement, but who has the time to do it. We'll show you how to control catalina.out.
You only need to modify this line:
Log4j.appender.r.file=/usr/local/tomcat/logs/tomcat.log
Modify the path to your tomcat's logs directory, and if your system environment is configured with the CATALINA_HOME environment variable, you can configure it with ${catalina.home}/logs/tomcat.log.
The above log4j configuration records only the more important logs (warning warning, error errors, Fatal error fatal) to the Tomcat.log file in Tomcat's logs directory, the first message that is over 0 points per night triggers the renaming of Tomcat.log, appends the current date to the Tomcat.log file name, and produces a new tomcat.log.
The bad thing about using log4j Dailyrollingfileappender is that in order to generate a looping log file, you must output a log message to trigger, and if you use cron every night to process your log files, there is a problem. Tomcat's own FileLogger always resolves this issue by adding a date to the log file name of the day. I (Geoff) have written a custom log4j appender to mimic Tomcat's filelogger, which you can use for free (including source code). The separate technical tip has datedfileappender installation and configuration information.
Note: The new log4j 1.3.x Alpha beta version already supports rolling log files by day. Refer to log4j Version 1.3 and Apache tomcat for information on how to install and configure.
You can override the default logging level by following the last few lines of the configuration file to make a special configuration for your application. In a formal operating environment, you may want to minimize log output, and you can modify this line:
Log4j.rootlogger=info, R
For:
Log4j.rootlogger=error, R
Warning
Be careful when modifying the log output level to debug (especially like Log4j.logger.org.apache), which can cause a large number of logs and slow down your system to a considerable degree.