2016-03-14 25 views
0

我想在我的項目中顯示我的查詢日誌。 我設置了我的文件(log4j2.xml),但我沒有表現出來。如何在我的項目中的log4j2中顯示數據庫查詢?

log4j2.xml是

<Configuration> 
<Appenders> 
    <Console name="console" target="SYSTEM_OUT"> 
     <!--<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>--> 
     <PatternLayout pattern="%d %5p [%c] %m%n" /> 
    </Console> 
    <Console name="console-mamoru" target="SYSTEM_OUT"> 
     <PatternLayout pattern="[MAMORU] (%d) [%5p] [%c] %m%n" /> 
    </Console> 
    <File name="file-mamoru" fileName="C:/logs/springweb/filelog.log" append="false"> 
     <PatternLayout pattern="[MAMORU-FILELOG] (%d) [%5p] [%c] %m%n" /> 
    </File> 
</Appenders> 
<Loggers> 
    <Logger name="org.springframework" level="INFO" additivity="false"> 
     <AppenderRef ref="console" /> 
    </Logger> 
    <Logger name="java.sql." level="INFO" additivity="false"> 
     <AppenderRef ref="console" /> 
    </Logger> 
    <Logger name="com.mamoru" level="DEBUG" additivity="false"> 
     <AppenderRef ref="console-mamoru"/> 
     <AppenderRef ref="file-mamoru"/> 
    </Logger> 
    <Root level="DEBUG"> 
     <AppenderRef ref="console"/> 
    </Root> 
</Loggers> 

我的日誌是:

2016年3月14日16:33:29228 INFO [org.springframework.test.context.support .DefaultTestContextBootstrapper]從位置[META-INF/spring.factories]加載默認TestExecutionListener類名稱:[org.springframework.test.context.web.ServletTestExecutionListener,org.springframework.test.context.support.DirtiesContextBeforeModesTestE xecutionListener,org.springframework.test.context.support.DependencyInjectionTestExecutionListener,org.springframework.test.context.support.DirtiesContextTestExecutionListener,org.springframework.test.context.transaction.TransactionalTestExecutionListener,org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] 2016-03-14 16:33:29,239信息[org.springframework.test.context.support.DefaultTestContextBootstrapper]無法實例化TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener]。指定自定義偵聽器類或使缺省偵聽器類(及其必需的依賴項)可用。 Offending類:[org/springframework/transaction/interceptor/TransactionAttributeSource] 2016-03-14 16:33:29,246信息[org.springframework.test.context.support.DefaultTestContextBootstrapper]無法實例化TestExecutionListener [org.springframework.test。 context.jdbc.SqlScriptsTestExecutionListener。指定自定義偵聽器類或使缺省偵聽器類(及其必需的依賴項)可用。 Offending類:[org/springframework/transaction/interceptor/TransactionAttribute] 2016-03-14 16:33:29,249 INFO [org.springframework.test.context.support.DefaultTestContextBootstrapper] Using TestExecutionListeners:[org.springframework.test.context .web.ServletTestExecutionListener @ 19aeb7a6,org.springframework.test[email protected]1d9b0076,org.springframewor[email protected]2b3b5229,org.springfra[email protected]438f17eb] 2016 -03-14 16:33:29,558 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]從URL加載XML bean定義[file:/ C:/ mamoru/github/spring/springweb/target/classes/spring/root-context.xml] 2016-03-14 16:33:30,747 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]從URL加載XML bean定義[file:/ C:/ mamoru/github /spring/springweb/target/classes/spring/springwebServlet/servlet-context-common.xml] 2016-03-14 16:33:31,080信息[org.springframework.beans.factory.xml.XmlBeanDefinitionReader]加載XML bean定義從URL [file:/ C:/mamoru/github/spring/springweb/target/classes/spring/springwebServlet/servlet-context-datasource.xml] 2016-03-14 16:33:31,120 INFO [org.springframework。 context.support.GenericApplicationContext]刷新[email protected]f69ae7:啓動日期[Mon Mar 14 16:33:31 KST 2016];上下文層次根 2016-03-14 16:33:31,652 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]將公共org.springframework.web映射爲「{[/ helloSpring]}」。 servlet.ModelAndView com.mamoru.webapp.hellospring.controller.HelloSpringController.hello() 2016-03-14 16:33:31,871信息[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]尋找@ ControllerAdvice:[email protected]f69ae7:啓動日期[Mon Mar 14 16:33:31 KST 2016];上下文層次結構的根 2016-03-14 16:33:31,964 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]尋找@ControllerAdvice:org.springframework.context.support。GenericApplicationContext @ 40f69ae7:啓動日期[Mon Mar 14 16:33:31 KST 2016];上下文層次結構的根 2016-03-14 16:33:32,090 INFO [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping]映射到處理程序'org.springframework.web.servlet的URL路徑[/ resources/**]。 (2016-03-14 16:33:32,124)[DEBUG] [com.mamoru.common.database.DBConnector] [DBConnector構造函數加載] [MAMORU](2016-03-14)[MAMORU] 14 16:33:32,136)[DEBUG] [com.mamoru.common.database.DBConnector] [Init DB Connector] START ======================= ==================================== [MAMORU](2016-03-14 16:33: 32,212)[DEBUG] [com.mamoru.common.database.DBConnector] [Init DB Connector] END ============================ ================================= [MAMORU](2016-03-14 16:33:33,298)[ DEBUG] [com.mamoru.common.database.DBConnectorTest] [數據列表] OBJECTID [MAMOR U](2016-03-14 16:33:33,299)[DEBUG] [com.mamoru.common.database.DBConnectorTest] [數據列表] REV [MAMORU](2016-03-14 16:33:33,299)[ DEBUG] [com.mamoru.common.database.DBConnectorTest] [數據列表] LINKTYPE [MAMORU](2016-03-14 16:33:33,299)[DEBUG] [com.mamoru.common.database.DBConnectorTest] [Data (2016-03-14 16:33:33,299)[DEBUG] [com.mamoru.common.database.DBConnectorTest] [數據列表] FIRSTID [MAMORU](2016-03-14 16: 33:33,299)[DEBUG] [com.mamoru.common.database.DBConnectorTest] [Data List] SECONDID 2016-03-14 16:33:33,302 INFO [org.springframework.context.support.GenericApplicationContext]關閉org.springframework .context.support.GenericApplicationContext @ 40f69ae7:啓動日期[Mon Mar 14 16:33:31 KST 2016];上下文層次結構的根

如何顯示我的查詢日誌?

回答

0

可能您的數據庫框架將查詢記錄爲INFO(如hibernate所做的那樣)。因此,修改的log4j-配置:

<!-- ... --> 
 
    <Logger name="com.mamoru" level="INFO" additivity="false"> 
 
      <AppenderRef ref="console-mamoru"/> 
 
      <AppenderRef ref="file-mamoru"/> 
 
    </Logger> 
 
<!-- ... -->

+0

這是不行的。 com.mamoru不調用數據庫日誌。 java.sql不起作用。這是我的問題。 – fightingmamoru

相關問題