简体   繁体   中英

Can't print to console with log4j

My problem is that I want to know how many connections are opened to the oracledb in an oracle datasource pool (oracle.jdbc.pool.OracleDataSource) and I want to print this information to the console using log4j. I defined my pool in a spring configuration file:

<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" >
    <property name="dataSourceName" value="ds" />   
    <property name="URL" value="jdbc:oracle:thin:@something" />
    <property name="user" value="user" />
    <property name="password" value="password" />
</bean>

I would pass somehow the log's informations in my ojdbc6 or ojdbc14 jars to the console with log4j as I said but my log4j doesn't print anything. In my log4j.properties I have:

log4j.logger.oracle.jdbc.pool=ALL, jdbc
log4j.appender.jdbc=org.apache.log4j.ConsoleAppender
log4j.appender.jdbc.layout=org.apache.log4j.PatternLayout
log4j.appender.jdbc.layout.ConversionPattern=JDBC    | %5p | %d{HH:mm:ss,SSS} > %m - [%l]%n 

I don't know if there are these kind of informations in ojdbc bundles, ok and if you know how can I have you're welcome, but my problem is that I can't see any logs. Maybe there aren't any logs at all...

Thank you for your attention.

there is no guarantee oracle uses log4j, you should try to configure java util logging settings. This link seems to suggest oracle uses java util logging. Alternatively you could build a proxy class or extend this class and write your own log4j messages before/after delegating back to the oracle connection pool.

Check this page to initialize the configurator. If you don't initialize it properly log4j wont log messages. Most importantly try to use log.debug, log.warn in the business logic which makes use of oracle objects. Log4j is a just a logging library which you can use through java. Not sure if oracle dumps it via that.

There are other tracing and logging tools if you think its not working fine. My first pointer would be try a simple app in your application to see if your console gets the log4j messages when you run them after using the configurator i mentioned previously.

I found the answer, only some ojdbc bundles are able to print logs. I have ojdbc6 and ojdbc14 jars and they haven't this ability.

From this link .

When full logging is enabled, it is almost guaranteed that all sensitive information will be exposed in the log files. This is intrinsic to the logging feature. However, only certain JDBC JAR files include the JDBC logging feature. The following JAR files include full logging and should not be used in a sensitive environment:

ojdbc5_g.jar

ojdbc5dms_g.jar

ojdbc6_g.jar

ojdbc6dms_g.jar

The following JAR files include a limited logging capability:

ojdbc5dms.jar

ojdbc6dms.jar

I'm done :P

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM