When Tomcat runs for only one day, the disk space Suddenly increases a lot. if it finds that the log file is too large, modify the log configuration of Tomcat.
View the space occupied by the directory:
[[email protected] webapps]du -sh
Cleaning Method:
[[email protected] logs]# cat > catalina.out
It is best to use log4 logs. The following describes how to configure Tomcat and log4.
1. Download The tomcat-juli.jar and tomcat-juli-adapters.jar corresponding to tomcat version, and log4j-1.2.17.jar, put in Tomcat/lib directory
Because of poor network, Maven download in eclipse, found tomcat-Juli-adapters package dependency tomcat-extras-juli.jar also copy it
2. Modify the tomcat/bin/Catalina. Sh file.
Comment out row 3 and the result is # Touch "$ catalina_out"
Modify row 394th. The result is
org.apache.catalina.startup.Bootstrap "[email protected]" start 2>&1 | /usr/local/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out >> /dev/null &
3. Create log4j. properties in Tomcat/lib
Log4j. appender. console = org. apache. log4j. leleappender log4j. appender. console. encoding = UTF-8 log4j. appender. console. layout = org. apache. log4j. patternlayout log4j. appender. console. layout. conversionpattern = % d [% T] %-5 p % C-% m % N log4j. appender. catalina = org. apache. log4j. dailyrollingfileappender log4j. appender. catalina. file =$ {Catalina. base}/logs/Catalina. log4j. appender. catalina. encoding = UTF-8 log4j. appender. catalina. datepattern = '. 'yyyy-mm-dd '. log'log4j. appender. catalina. layout = org. apache. log4j. patternlayout log4j. appender. catalina. layout. conversionpattern = % d [% T] %-5 p % C-% m % N log4j. appender. catalina. append = true log4j. appender. localhost = org. apache. log4j. dailyrollingfileappender log4j. appender. localhost. file =$ {Catalina. base}/logs/localhost. log4j. appender. localhost. encoding = UTF-8 log4j. appender. localhost. datepattern = '. 'yyyy-mm-dd '. log' # log4j. appender. localhost. maxfilesize = 100 MB # log4j. appender. localhost. maxbackupindex = 10 log4j. appender. localhost. layout = org. apache. log4j. patternlayout log4j. appender. localhost. layout. conversionpattern = % d [% T] %-5 p % C-% m % N log4j. appender. localhost. append = true log4j. appender. manager = org. apache. log4j. dailyrollingfileappender log4j. appender. manager. file =$ {Catalina. base}/logs/manager. log4j. appender. manager. encoding = UTF-8 log4j. appender. manager. datepattern = '. 'yyyy-mm-dd '. log'log4j. appender. manager. layout = org. apache. log4j. patternlayout log4j. appender. manager. layout. conversionpattern = % d [% T] %-5 p % C-% m % N log4j. appender. manager. append = true log4j. appender. host-Manager = org. apache. log4j. dailyrollingfileappender log4j. appender. HOST-MANAGER.file =$ {Catalina. base}/logs/Host-manager. log4j. appender. HOST-MANAGER.encoding = UTF-8 log4j. appender. HOST-MANAGER.datePattern = '. 'yyyy-mm-dd '. log'log4j. appender. the HOST-MANAGER.layout = org. apache. log4j. patternlayout log4j. appender. HOST-MANAGER.layout.conversionPattern = % d [% T] %-5 p % C-% m % N log4j. appender. HOST-MANAGER.append = true # Send Logs to the mail # log4j. appender. mail = com. gamaxpay. commonutil. log4j. smtpappender # log4j. appender. mail. threshold = Error # log4j. appender. mail. buffersize = 1024 # log4j. appender. mail. smtphost = smtp.exmail.qq.com # log4j. appender. mail. subject = Error Log # [email protected] # log4j. appender. mail. smtppassword = mokreditwin2012 # [email protected] # [email protected] # log4j. appender. mail. allowsendemail = false # log4j. appender. mail. layout = org. apache. log4j. patternlayout # log4j. appender. mail. layout. conversionpattern = % d {yyyy-mm-dd hh: mm: SS} [% P] [% T] % L: % m % N # Root logger # log4j. rootlogger = info, console, Catalina, mail log4j.logger.org. springframework. web. servlet. handler. simpleurlhandlermapping = warn log4j.logger.org. springframework. beans. factory. XML. xmlbeandefinitionreader = warn log4j.logger.org. hibernate. cfg. annotations. entitybinder = warn log4j.logger.org. hibernate. cfg. annotationbinder = warn log4j.logger.org. hibernate. cfg. annotations. collectionbinder = warn log4j.logger.org. apache. catalina. core. containerbase. [Catalina]. [localhost] = info, localhost log4j.logger.org. apache. catalina. core. containerbase. [Catalina]. [localhost]. [/manager] = info, Manager log4j.logger.org. apache. catalina. core. containerbase. [Catalina]. [localhost]. [/Host-manager] = info, host-manager log4j.logger.de. javakaffee. web. MSM = Error log4j.logger.org. apache. catalina. core = info, localhost log4j.logger.org. apache. catalina. session = info, localhost
4, create a commons-logging.properties, put $ catalina_home/lib, the file content is as follows:
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
5. Restart tomcat to observe the log files in logs.
Note: In the window local measurement found that, do not put the log4j-1.2.17.jar can be used.
The generated log files are concise and much better than those provided by Tomcat.