Configure the LOG4JDBC data source through WebLogic, use the data source in your project, output SQL

Source: Internet
Author: User
Tags log4j

Configure the LOG4JDBC data source through WebLogic, use the data source in your project, output SQL
Say the configuration: The server WebLogic Project uses spring management beans, the data source configuration is a spring-based DBCP data source, and the SQL log is printed with LOG4JDBC with logback+slf4j logs. Log4jdbc is able to print SQL well, and parameters are also taken, which can be very helpful in the development of the project and the cause of problems in the later system. The database configuration is as follows: Jdbc.driverclassname=net.sf.log4jdbc.driverspyjdbc.url=jdbc:oracle:thin: @ip:p Ort/dev
Jdbc.username=user
Jdbc.password=pwd
The spring configuration is as follows: <bean id= "DataSource" class= "Org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy" >
<property name= "Targetdatasource" >
<ref local= "Maindatasource"/>
</property>
</bean>
<bean id= "Maindatasource" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" >
<property name= "Driverclassname" value= "${jdbc.driverclassname}"/>
<property name= "url" value= "${jdbc.url}"/>
<property name= "username" value= "${jdbc.username}"/>
<property name= "Password" value= "${jdbc.password}"/>
<property name= "initialsize" value= "/>"
<property name= "logabandoned" value= "true"/>
<property name= "maxactive" value= "/>"
<property name= "maxwait" value= "310000"/>
<property name= "Minidle" value= "2"/>
<property name= "maxopenpreparedstatements" value= "/>"
<property name= "removeabandoned" value= "true"/>
<property name= "removeabandonedtimeout" value= "/>"
<property name= "Poolpreparedstatements" value= "false"/>
<property name= "Defaultautocommit" value= "true"/>
</bean>

Later in the project, the customer requested that the data source for the project configuration not be used, to use the WebLogic data source. The customer is big, so changed, changed, LOG4JDBC's SQL no longer print out. This is the configuration of the WebLogic data source:
Before the project has SQL print, LOG4JDBC can also print out the parameters of SQL execution so that the project execution can be known. Without SQL, if there is a problem, it is not good to locate the problem, so in order to print out the SQL test.
The spring configuration should read as follows: <bean id= "DataSource" class= "Org.springframework.jndi.JndiObjectFactoryBean" >
<property name= "Jndiname" >
<value>lmsDatasource</value>
</property>
<property name= "Resourceref" >
<value>false</value>
</property>
<property name= "Jndienvironment" >
<props>
<!--the value of Context.provider_url, which is the URL to configure WebLogic, such as t3://127.0.0.1:7001---
<prop key= "Java.naming.provider.url" >t3://ip:weblogicport</prop>
<prop key= "Java.naming.factory.initial" >weblogic.jndi.WLInitialContextFactory</prop>
</props>
</property>
Change the </bean>weblogic data source to the following configuration:
Load the driver, There are several jar packages that need to be used: Log4jdbc3-1.2beta2.jarlogback-classic-1.1.1.jarlogback-core-1.1.1.jarslf4j-api-1.6.4.jar and WebLogic When starting to load these J AR pack. In an article (http://blog.csdn.net/yjq8116/article/details/4498622), we see that a third-party jar package is automatically loaded by placing the jar directly in {domain_home}/lib. But I did it without taking effect. Placing the jar package under {Wls_home}/server/lib does not take effect, the path of the third-party jar package is loaded in the JDK directory: {java_home}/jre/lib/ext, this can be loaded, but this will take effect on all local Java programs, Will affect other projects, so it should not be placed in that directory.
Also want to continue to think of ways, why plainly WebLogic himself also said can automatically load {domain_home}/lib jar, but not loaded, baffled its solution.
Later in the WebLogic boot log, see the following fragment:
This is the path configuration of the third-party jar package that WebLogic loaded, but it was not found. I saw it in {domain_home}/bin/setdomainenv.sh.
This weblogic.ext.dirs is the classpath loaded in WebLogic's console. Therefore, it is possible to manually add this path directly so that WebLogic can load the third-party jar package at startup.
This is the modified, variable ${domain_home} before the file, WebLogic the existing definition.

After modification, start WebLogic, execute command in {domain_home}: Nohup./startweblogic.sh >./logs/weblogic "' Date +%y%m%d%h%m '". Log 2>&1 & Start, found that the console print a lot of logs, are the debug level (about the level of log, the project is to use Logback, you can find relevant information), this is the lowest level, all the logs will be output, Obviously this output does not make much sense to us, and it also affects the performance of the system.


However, the print of the journal is printed according to a custom format, why does the WebLogic print such a configuration, and is it the debug level? Later on the internet to find out about the WebLogic log configuration problem, found this article: http://bbs.middleware123.com/forum.php?mod=viewthread&tid=4532, which says you can configure the command Set Log4j_config_file=/root/bea/user_projects/domains/medrecdomain/log4jconfig.xml To configure log4j files (logback and log4j are log systems, the specific differences can be found in the relevant information). And really found this configuration in the setdomainenv.sh file:

I think for the programmer, although do not understand the shell, but see this also probably know this meaning, if there are variables: log4j_config_file, add to Java_properties, I do not know what this java_properties is doing, But change it, maybe it works. Suddenly feel for this weblogic, really many can only go to try. The following configuration is added:

Here is my logback.xml's main configuration <?xml version= "1.0" encoding= "UTF-8"?>
<configuration>
<!--log output to file--
<appender name= "rolling" class= "Ch.qos.logback.core.rolling.RollingFileAppender" >
<file>logs/weblogiclog.txt</file>
<rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" >
<!--rollover Daily--
<fileNamePattern>logs/weblogiclog-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>10</maxHistory>
<timebasedfilenamingandtriggeringpolicy
class= "Ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP" >
<!--or whenever the file size reaches 100MB--
<maxFileSize>500MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>

<!--<pattern>%date%level [%thread]%logger{36} [%file:%line]%msg%n</pattern>-
&LT;PATTERN&GT;%D{YY/MM/DD HH:mm:ss}%5level [%c{1}.%m\ (%l\)]%m%n</pattern>
</encoder>
</appender>
<!--log output to console--
<appender name= "STDOUT" class= "Ch.qos.logback.core.ConsoleAppender" >
<encoder>
<!--<pattern>%date%5level [%thread]%logger{36} [%file:%line]%msg%n</pattern>-
<!--only Show method name and Line no
&LT;PATTERN&GT;%D{YY/MM/DD HH:mm:ss}%5level [%c{1}.%m\ (%l\)]%m%n</pattern>--
<!--Show Method caller-->
<pattern>%d{yy/mm/dd HH:mm:ss}%5level%caller{1}-%msg%n</pattern>
</encoder>
</appender>

<logger name= "com.sinoservices" level= "ERROR" additivity= "false" >
<appender-ref ref= "STDOUT"/>
</logger>
<logger name= "jdbc.sqlonly" level= "INFO" >
<!--add SQL Print console--
<appender-ref ref= "STDOUT"/>
<appender-ref ref= "STDOUT"/>
</logger>
<logger name= "jdbc.sqltiming" level= "OFF" >
<appender-ref ref= "Rolling"/>
</logger>
<logger name= "Jdbc.audit" level= "OFF" >
<appender-ref ref= "Rolling"/>
</logger>
<logger name= "Jdbc.resultset" level= "OFF" >
<appender-ref ref= "Rolling"/>
</logger>
<logger name= "jdbc.connection" level= "OFF" >
<appender-ref ref= "Rolling"/>
</logger>
<root level= "INFO" >
<appender-ref ref= "Rolling"/>
</root>
</configuration> The following is the console of the final WebLogic, the record of the print log is indeed consistent with the logback.xml of my configuration, I can print the SQL parameters, and before {domain_home}/logs/ The catalog does not appear with logs/weblogiclog.txt scrolling logs, and now there are. For a long time, finally got out:



In fact, in the project also has logback configuration, configuration of Logger Appender is: <appender name= "rolling" class= " Ch.qos.logback.core.rolling.RollingFileAppender ">
<file>logs/log.txt</file>
<rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" >
<!--rollover Daily--
<fileNamePattern>logs/log-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>10</maxHistory>
<timebasedfilenamingandtriggeringpolicy
class= "Ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP" >
<!--or whenever the file size reaches 100MB--
<maxFileSize>500MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<!--<pattern>%date%level [%thread]%logger{36} [%file:%line]%msg%n</pattern>-
&LT;PATTERN&GT;%D{YY/MM/DD HH:mm:ss}%5level [%c{1}.%m\ (%l\)]%m%n</pattern>
</encoder>
</appender>
After another test, found that the WebLogic Logback configuration can only be placed under the domain. And if placed directly in the domain directory, you can also do not need log4j_config_file configuration. Tried again several times in other directories, found not effective, do not know whether it can only be placed in the domain directory.
However, the configuration used in the project was not generated and the Log.txt file was not generated. This can be generated before, after changing such a data source, do not come out, do not know is not because the WebLogic itself has supported the support of Logback, so the project Logback configured to be shielded?

Configure the LOG4JDBC data source through WebLogic, use the data source in your project, output SQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.