How to show database query in log4j2 in my project?

I want to show my query log in my poject. I set my file (log4j2.xml), But I don`t show that.

log4j2.xml is

<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>

My log is :

2016-03-14 16:33:29,228 INFO [org.springframework.test.context.support.DefaultTestContextBootstrapper] Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, 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 INFO [org.springframework.test.context.support.DefaultTestContextBootstrapper] Could not instantiate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource] 2016-03-14 16:33:29,246 INFO [org.springframework.test.context.support.DefaultTestContextBootstrapper] Could not instantiate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [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.context.support.DirtiesContextBeforeModesTestExecutionListener@1d9b0076, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@2b3b5229, org.springframework.test.context.support.DirtiesContextTestExecutionListener@438f17eb]2016-03-14 16:33:29,558 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] Loading XML bean definitions from URL [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] Loading XML bean definitions from URL [file:/C:/mamoru/github/spring/springweb/target/classes/spring/springwebServlet/servlet-context-common.xml] 2016-03-14 16:33:31,080 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] Loading XML bean definitions from 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] Refreshing org.springframework.context.support.GenericApplicationContext@40f69ae7: startup date [Mon Mar 14 16:33:31 KST 2016]; root of context hierarchy 2016-03-14 16:33:31,652 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] Mapped "{[/helloSpring]}" onto public org.springframework.web.servlet.ModelAndView com.mamoru.webapp.hellospring.controller.HelloSpringController.hello() 2016-03-14 16:33:31,871 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] Looking for @ControllerAdvice: org.springframework.context.support.GenericApplicationContext@40f69ae7: startup date [Mon Mar 14 16:33:31 KST 2016]; root of context hierarchy 2016-03-14 16:33:31,964 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] Looking for @ControllerAdvice: org.springframework.context.support.GenericApplicationContext@40f69ae7: startup date [Mon Mar 14 16:33:31 KST 2016]; root of context hierarchy 2016-03-14 16:33:32,090 INFO [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0' [MAMORU] (2016-03-14 16:33:32,124) [DEBUG] [com.mamoru.common.database.DBConnector] [DBConnector constructor load] [MAMORU] (2016-03-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] [Data List] OBJECTID [MAMORU] (2016-03-14 16:33:33,299) [DEBUG] [com.mamoru.common.database.DBConnectorTest] [Data List] REV [MAMORU] (2016-03-14 16:33:33,299) [DEBUG] [com.mamoru.common.database.DBConnectorTest] [Data List] LINKTYPE [MAMORU] (2016-03-14 16:33:33,299) [DEBUG] [com.mamoru.common.database.DBConnectorTest] [Data List] LINKQUALIFIER [MAMORU] (2016-03-14 16:33:33,299) [DEBUG] [com.mamoru.common.database.DBConnectorTest] [Data List] 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] Closing org.springframework.context.support.GenericApplicationContext@40f69ae7: startup date [Mon Mar 14 16:33:31 KST 2016]; root of context hierarchy

How can I show my query log?

Answers


Probably your database frameworks logs the queries as INFO (as hibernate does). So modify your log4j-config:

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

Need Your Help

REST calls in Android studio (post 2014 - IntelliJ based)

android rest android-studio

There are plug-ins for Eclipse, where we can see the REST conversation logs.

JVM meant to call main() and finalize() both, one is public and other is protected ? why?

java jvm main finalize

I was searching answer for finalize method made protected in object class, I came accross the answer and finally got confused as i found For finalize() method of object class it has been said that ...