2010/08/06

[Java] 修改 jForum 預設的 log 等級

最近在研究這一套 open source 的論壇, 一裝起來就發現有一些擾人的 java.sql.SQLWarning 跑出來.
例如:

java.sql.SQLWarning: Changed database context to 'myjforum'. 
        at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:390) 
        … 
        at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:119) 
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:143) 
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:132) 
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137) 
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014) 
        at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) 
        at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810) 
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547) 
或是
java.sql.SQLWarning: Changed language setting to us_english. 
        at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:390) 
        … 
        at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:119) 
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:143) 
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:132) 
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137) 
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014) 
        at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32) 
        at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810) 
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

原來 jForum2.1.8 預設所使用的資料庫連線套件是 c3p0 .
其中, jForum 有另外寫了一個 net.jforum.C3P0PooledConnection.java 並讀取 \WEB-INF\config\SystemGlobals.properties 中的 c3p0.extra.params 參數進行設定.
到這邊為止, c3p0 的基本設定都可以參考官網的說明文件來完成.
但 logging 的部分卻不是在上述的設定檔中設定, 而是寫在 \WEB-INF\log4j.xml 裡.
打開 \WEB-INF\log4j.xml , 就可以找到許多有關 jForum的 log 設定, 而且預設很多 log 等級都設定在 info.
有關 c3p0 的 log 設定是在:
<category name="com.mchange"> 
  <priority value="info" /> 
  <appender-ref ref="jforum-stdout" /> 
</category>
log 等級的設定只要參考 log4j 的 Introduction 說明, 設定 TRACE, DEBUG, INFO, WARN, ERROR, FATAL 當中一個即可.
附帶一提, jForum2.1.8 使用了 freemarker 進行套版. 所以如果後續要更改該套件的 log 等級, 一樣是在 \WEB-INF\log4j.xml 中進行修改, 修改項目是:
<category name="freemarker"> 
  <priority value="info"/> 
  <appender-ref ref="jforum-stdout"/>         
</category>   

沒有留言: