Resource URL: http://download.csdn.net/detail/attagain/7771065
The default Log File Catalina. Out generated by Tomcat increases gradually over time, possibly reaching the g level. If the file is too large, we will not be able to use regular editing tools to view it, seriously affecting system maintenance. To solve this problem, we mainly consider Tomcat and code.
I. Code considerations
Tomcat outputs the Catalina. Out file. The main data sources are system. Out and system. Err. To reduce the pressure on log output and standardize code habits, you should avoid using system. Out. println () and E. printstacktrace () During encoding ().
Ii. tomcat configuration considerations
1. Tomcat uses log4j
This method is not discussed here.
2. tomcat configuration
When deploying a service, you can add the swallowoutput attribute to the context to reduce the output of console logs.
3. Use the cronolog tool for segmentation
A. Download The cronolog Tool
Official URL: http://cronolog.org/download/index.html
B. Compile and install cronolog
[[Email protected] ~] $ Tar xvf cronolog-1.6.2.tar.gz
[[Email protected] cronolog-1.6.2] $./configure
[[Email protected] cronolog-1.6.2] $ make
[[Email protected] cronolog-1.6.2] $ sudo make install
C. Modify the Tomcat STARTUP script Catalina. Sh.
A. Modify the output Log Path
Modify:
If [-z "$ catalina_out"]; then
Catalina_out = "$ catalina_base"/logs/Catalina. Out
Fi
Is:
If [-z "$ catalina_out"]; then
Catalina_out = "$ catalina_base"/logs/Catalina. % Y-% m-% d. Out
Fi
B. Delete the generated log file
Note:
Touch "$ catalina_out"
Is:
# Touch "$ catalina_out"
C. Modify Startup Script Parameters
Modify:
Org. Apache. Catalina. startup. Bootstrap "[email protected]" Start \
> "$ Catalina_out" 2> & 1 "&"
Is:
Org. Apache. Catalina. startup. Bootstrap "[email protected]" Start 2> & 1 \
|/Usr/local/sbin/cronolog "$ catalina_out">/dev/null &
D. Restart tomcat.
Tomcat output log files are separated successfully. The output log file format is catalina.2014-08-15.out.
Size Control of Tomcat output Catalina. Out