2012-04-17 31 views
4

我的Java應用程序(Spring,Hibernate,MySQL)運行在Tomcat 5.5中Tomcat catalina.out文件增長非常迅速!如何防止將Hibernate的INFO和DEBUG語句添加到catalina.out文件中?

對我的應用程序進行最後一組更改後,Tomcat的catalina.out文件增長非常迅速。隨着每個查詢它增加了INFO和DEBUG語句幾MB上的文件

日誌文件中有非常多的信息和調試語句,如下列:log4j.properties的

01:52:45.412 [main] INFO o.hibernate.cfg.annotations.Version - Hibernate Annotations 3.5.6-Final 
01:52:45.465 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.6-Final 
01:52:45.468 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found 
01:52:45.473 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist 
01:52:45.479 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling 
01:52:45.629 [main] DEBUG o.h.i.f.DefaultIdentifierGeneratorFactory - Registering IdentifierGenerator strategy [uuid] -> [class org.hibernate.id.UUIDHexGenerator] 
01:52:45.635 [main] DEBUG o.h.i.f.DefaultIdentifierGeneratorFactory - Registering IdentifierGenerator strategy [hilo] -> [class org.hibernate.id.TableHiLoGenerator] 
01:52:45.636 [main] DEBUG o.h.i.f.DefaultIdentifierGeneratorFactory - Registering IdentifierGenerator strategy [assigned] -> [class org.hibernate.id.Assigned] 
01:52:45.639 [main] DEBUG o.h.i.f.DefaultIdentifierGeneratorFactory - Registering IdentifierGenerator strategy [identity] -> [class org.hibernate.id.IdentityGenerator] 
01:52:45.640 [main] DEBUG o.h.i.f.DefaultIdentifierGeneratorFactory - Registering IdentifierGenerator strategy [select] -> [class org.hibernate.id.SelectGenerator] 


01:52:45.668 [main] INFO o.h.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final 
01:52:45.719 [main] DEBUG o.h.cfg.AnnotationConfiguration - Execute first pass mapping processing 
01:52:45.780 [main] DEBUG o.h.cfg.AnnotationConfiguration - Process hbm files 
01:52:45.780 [main] DEBUG o.h.cfg.AnnotationConfiguration - Process annotated classes 
01:52:45.791 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.knownomy.scl.appcommon.domain.Language 
01:52:45.805 [main] INFO o.h.cfg.annotations.QueryBinder - Binding Named query: language.id => from Language language where language.id = ? 
01:52:45.821 [main] DEBUG org.hibernate.cfg.Ejb3Column - Binding column: Ejb3DiscriminatorColumn{logicalColumnName'DTYPE', discriminatorTypeName='string'} 
01:52:45.824 [main] DEBUG org.hibernate.cfg.AnnotationBinder - no value specified for 'javax.persistence.sharedCache.mode'; using UNSPECIFIED 
01:52:45.843 [main] DEBUG o.h.cfg.annotations.EntityBinder - Import with entity name Language 
01:52:45.849 [main] INFO o.h.cfg.annotations.EntityBinder - Bind entity com.knownomy.scl.appcommon.domain.Language on table language 

01:52:50.164 [main] DEBUG o.h.hql.ast.QueryTranslatorImpl - parse() - HQL: from com.knownomy.scl.quiz.domain.Question question where question.chapter.id=? and question.questionSource.id=? and question.mcq.questionText=? 
01:52:50.177 [main] DEBUG org.hibernate.hql.ast.AST - --- HQL AST --- 
\-[QUERY] Node: 'query' 
    +-[SELECT_FROM] Node: 'SELECT_FROM' 
    | \-[FROM] Node: 'from' 
    |  \-[RANGE] Node: 'RANGE' 
    |  +-[DOT] Node: '.' 
    |  | +-[DOT] Node: '.' 
    |  | | +-[DOT] Node: '.' 
    |  | | | +-[DOT] Node: '.' 
    |  | | | | +-[DOT] Node: '.' 
    |  | | | | | +-[IDENT] Node: 'com' 
    |  | | | | | \-[IDENT] Node: 'knownomy' 
    |  | | | | \-[IDENT] Node: 'scl' 
    |  | | | \-[IDENT] Node: 'quiz' 
    |  | | \-[IDENT] Node: 'domain' 
    |  | \-[IDENT] Node: 'Question' 
    |  \-[ALIAS] Node: 'question' 
    \-[WHERE] Node: 'where' 

內容: application.properties文件

log4j.rootLogger=INFO, stdout, R 

log4j.appender.stdout=org.apache.log4j.ConsoleAppender 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 
log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{yyyy-MM-dd HH:mm:ss} (%F:%M:%L) - %m%n 

log4j.appender.R=org.apache.log4j.RollingFileAppender 
log4j.appender.R.File=${catalina.home}/logs/SmartCloudLearningMobi.log 
log4j.appender.R.MaxFileSize=10MB 
log4j.appender.R.MaxBackupIndex=10 
log4j.appender.R.layout=org.apache.log4j.PatternLayout 
log4j.appender.R.layout.ConversionPattern=[%5p] %d{yyyy-MM-dd HH:mm:ss} (%F:%M:%L) - %m%n 

log4j.logger.org.hibernate=ERROR, stdout, R 
log4j.logger.org.hibernate.type=ERROR, stdout, R 
log4j.logger.org.hibernate.SQL=ERROR, stdout, R 
log4j.logger.org.hibernate.tool.hbm2ddl=ERROR, stdout, R 
log4j.logger.org.hibernate.cache=ERROR, stdout, R 
log4j.additivity.org.hibernate.SQL=false 
log4j.logger.org.springframework=ERROR, stdout, R 
log4j.logger.org.springframework.test.context.junit4.SpringJUnit4ClassRunner=ERROR, stdout, R 

內容:

# Application Properties 
path.webinf=webapps/SmartCloudLearningMobi/WEB-INF 
# JDBC Connection information 
jdbc.driverClassName=com.mysql.jdbc.Driver 
jdbc.url=jdbc:mysql://localhost:3306/databasename?useUnicode=true&characterEncoding=UTF8 
jdbc.username=root 
jdbc.password=mypassword 
###hibernate 
hibernate.show_sql=false 
hibernate.format_sql=true 
hibernate.transaction.factory_class=org.hibernate.transaction.JDBCTransactionFactory 
hibernate.dialect=org.hibernate.dialect.MySQLDialect 
hibernate.c3p0.min_size=1 
hibernate.c3p0.max_size=25 
hibernate.c3p0.acquire_increment=5 
hibernate.c3p0.timeout=1800 
hibernate.c3p0.max_statements=50 
hibernate.c3p0.idle_test_period=3600 

在過去昌E, 我刪除了以下jar文件:

ejb3-persistance.jar 

,並添加以下jar文件:

aspectjtools-1.5.4.jar 
bval-core-0.3-incubating.jar 
hibernate-validator-4.1.0.Final.jar 
jackson-core-asl-1.6.4.jar 
jackson-mapper-asl-1.6.4.jar 
joda-time-1.6.2.jar 
joda-time-jsptags-1.0.2.jar 
jstl-1.2.jar 
validation-api-1.0.0.GA.jar 

有人能告訴我如何防止Hibernate的INFO和DEBUG語句從被添加到該catalina.out中文件?非常感激。

更新: 根據我在網上找到的,我更新log4j.properties文件到以下幾點: log4j.rootLogger = INFO,stdout中,R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 
log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{yyyy-MM-dd HH:mm:ss} (%F:%M:%L) - %m%n 
#log4j.appender.stdout.layout.ConversionPattern=[%5p] %t %d{yyyy-MM-dd HH:mm:ss} (%F:%M:%L) - %m%n 

log4j.appender.R=org.apache.log4j.RollingFileAppender 
log4j.appender.R.File=${catalina.home}/logs/SmartCloudLearningMobi.log 
log4j.appender.R.MaxFileSize=10MB 
log4j.appender.R.MaxBackupIndex=10 
log4j.appender.R.layout=org.apache.log4j.PatternLayout 
log4j.appender.R.layout.ConversionPattern=[%5p] %d{yyyy-MM-dd HH:mm:ss} (%F:%M:%L) - %m%n 
#log4j.appender.R.layout.ConversionPattern=[%5p] %t %d{yyyy-MM-dd HH:mm:ss} (%F:%M:%L) - %m%n 

log4j.logger.org.hibernate=ERROR, stdout, R 

### log HQL parse trees 
log4j.logger.org.hibernate.hql=ERROR, stdout, R 

### Log HQL and SQL ASTs during query parsing ### 
log4j.logger.org.hibernate.hql.ast.AST=ERROR, stdout, R 
log4j.additivity.org.hibernate.hql.ast.AST=false 

### log just the SQL 
log4j.logger.org.hibernate.SQL=ERROR, stdout, R 
log4j.additivity.org.hibernate.SQL=false 

### log JDBC bind parameters. Very userfull, when debug parameterized queries ### 
log4j.logger.org.hibernate.type=ERROR, stdout, R 
log4j.additivity.org.hibernate.type=false 

### log schema export/update ### 
log4j.logger.org.hibernate.tool.hbm2ddl=ERROR, stdout, R 

### log cache activity ### 
log4j.logger.org.hibernate.cache=ERROR, stdout, R 

### log transaction activity 
log4j.logger.org.hibernate.transaction=ERROR, stdout, R 

### Log all JDBC resource acquisition 
log4j.logger.org.hibernate.jdbc=ERROR, stdout, R 

### enable the following line if you want to track down connection ### 
### leakages when using DriverManagerConnectionProvider ### 
log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=ERROR, stdout, R 

log4j.logger.org.hibernate.cfg=ERROR, stdout, R 


log4j.logger.org.springframework=ERROR, stdout, R 
log4j.logger.org.springframework.test.context.junit4.SpringJUnit4ClassRunner=ERROR, stdout, R 

但它並沒有區別!我仍然在catalina.out文件中看到相同的日誌語句!我該如何解決這個問題?任何人?

回答

2

最有可能發生的事情是,它不是Log4j正在做日誌記錄。它可能是Tomcat的JULI記錄器。你應該看看

http://tomcat.apache.org/tomcat-5.5-doc/logging.html

,並確保log4j的是設置正確(即,使得它使用它,而不是其默認的日誌記錄系統)

+0

Adam,感謝您的建議。正如我在日誌上做了更多的閱讀,似乎我可能需要爲我添加到應用程序的新jar文件添加日誌記錄語句,就像我在log4j中有「log4j.logger.org.hibernate = ERROR,stdout,R」一樣。將org.hibernate的日誌級別限制爲ERROR的屬性。它看起來像一個體面的角度來探索? – 2012-04-18 00:43:16

+0

如果您要編寫新代碼,請考慮查看slf4j作爲記錄器。我已經讓Slf4j能夠運行一些最困難的平臺(websphere),所以它應該可以與Tomcat 5.5一起工作。你應該考慮的另一個選擇是升級到Tomcat 6,因爲它非常穩定,並且做得更好。 – 2012-04-18 00:49:22

+0

我將以下內容添加到log4j.properties中,但它沒有區別!現在我打算查看JULI log4j.logger.org.hibernate.cfg = ERROR,stdout,R log4j.logger.org.hibernate.hql.ast = ERROR,stdout,R log4j.logger.ohcfg .annotations = ERROR,stdout,R log4j.logger.ohcannotations = ERROR,stdout,R log4j.logger.ohhql.antlr = ERROR,stdout,R log4j.logger.o.hibernate.hql.ast.tree =錯誤,標準輸出,R – 2012-04-18 14:51:42

0

我有同樣的問題,我這是怎麼了能夠與下面的步驟來解決:

  1. 導航到conf文件夾中tomcat主任(我有Tomcat設置的方式,地點是/usr/local/tomcat/conf。這可以根據Tomcat是如何安裝的)
  2. 編輯logging.properties文件應該有所不同(需要root訪問權限:vim sudo logging.properties或使用sudo su - root身份登錄,然後做vim logging.properties
  3. 變化
    .handlers = 1catalina.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler

    .handlers = 1catalina.org.apache.juli.AsyncFileHandler
  4. 保存並重新啓動Tomcat(/usr/local/tomcat/bin/shutdown.sh然後/usr/local/tomcat/bin/startup.sh

我也注意到我的tomcat日誌文件夾(/usr/local/tomcat/logs)非常龐大。要檢查日誌文件夾的大小,請執行以下操作du -hs /usr/local/tomcat/logs/。爲了解決這個問題,我安裝了一個可以每晚清理文件的cron,或者你可以手動運行這些命令。這裏是刪除5天以前的文件的shell腳本

#!/bin/sh 
find /usr/local/tomcat/logs -name 'catalina.*.log' -mtime +5 -print0 | xargs -0 rm -f 
find /usr/local/tomcat/logs -name 'localhost_access_log.*.txt' -mtime +5 -print0 | xargs -0 rm -f 
相關問題