标签:style java os io 文件 art ar cti
Tomcat运行仅一天磁盘空间突然就增加了很多,发现是日志文件太大了,修改tomcat的日志配置即可。
查看目录所占空间大小:
[root@XXX webapps]du -sh
清理方法:
[root@XXX logs]# cat > catalina.out
最好还是用log4日志,下面是配置Tomcat与log4的过程
1、下载与Tomcat相应版本的tomcat-juli.jar 和 tomcat-juli-adapters.jar,及log4j-1.2.17.jar,放在tomcat/lib目录中
因为网络不畅,在eclipse用Maven下载,发现tomcat-juli-adapters包依赖tomcat-extras-juli.jar也一并将其copy
2、修改tomcat/bin/catalina.sh文件
注释 第372行 ,结果为 # touch "$CATALINA_OUT"
修改第394行,更改的结果为
org.apache.catalina.startup.Bootstrap "$@" start 2>&1 | /usr/local/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out >> /dev/null &
3、创建log4j.properties放在tomcat/lib
log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.encoding = UTF-8 log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.conversionPattern = %d [%t] %-5p %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] %-5p %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 = 100MB #log4j.appender.LOCALHOST.maxBackupIndex = 10 log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout log4j.appender.LOCALHOST.layout.conversionPattern = %d [%t] %-5p %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] %-5p %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.HOST-MANAGER.layout = org.apache.log4j.PatternLayout log4j.appender.HOST-MANAGER.layout.conversionPattern = %d [%t] %-5p %c - %m%n log4j.appender.HOST-MANAGER.append = true ## 将日志发送到邮件 #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 #log4j.appender.MAIL.SMTPUsername=system@mo9.com.cn #log4j.appender.MAIL.SMTPPassword=mokreditwin2012 #log4j.appender.MAIL.From=system@mo9.com.cn #log4j.appender.MAIL.To=jian@mokredit.com #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、创建commons-logging.properties,放入$CATALINA_HOME/lib,文件内容如下:
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
5、重启Tomcat观察logs下的日志文件
后记:在window下本地实测时发现,放不放log4j-1.2.17.jar都可以用。
生成的日志文件简洁,比tomcat自带的好多了
Tomcat7 log4j配置,布布扣,bubuko.com
标签:style java os io 文件 art ar cti
原文地址:http://my.oschina.net/xldc/blog/298080