Get the name of the package from which a SQL query was fired?

前端 未结 1 1611
我在风中等你
我在风中等你 2021-01-23 00:01

I am using jdbcdslog with log4j logging engine in a webapp. I am able to log SQL queries that are executed. I want to know how to get the name of the package from which the quer

相关标签:
1条回答
  • 2021-01-23 00:47

    From the http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html I cant see any place where you can specify a variable for originating method. Also looking through the events log4j passes around it doesnt look like that information gets passed down the chain of events.(http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/LoggingEvent.html).

    However if you really need this functionality you could probably pull off some workaround involving implementing your own DataSourceProxyBase. I downloaded the jdbcdslog source from their download page, It looks like you can extend and override some methods from the DataSourceProxyBase class and add in your own logger. Then point your setup to use that data source proxy.

    <bean id="dataSourceActual" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>java:comp/env/jdbc/MyDatasource</value>
        </property>
    </bean>
    
    <bean id="dataSource" class="com.me.MySoureConnectionPoolDataSourceProxy">
        <property name="targetDSDirect" ref="dataSourceActual" />
    </bean>
    

    If you download the source you can start following their program around and see what you would need to override to implement what you need. A good starting place might be the class PooledConnectionLoggingProxy

    0 讨论(0)
提交回复
热议问题