sql statement Spool

 maven using log4j
1. log4j configuration mode:
Log4j configuration supports two ways, one is arranged in the code, one line is configured by using a configuration file. When using the configuration file to configure, Log4j supports two configuration file format An XML format file, one is the properties file format. 
In the project we generally use the configuration file to configure.
Here we introduce the properties manner configure log4j environment.

2. Add the log4j in pom.xml dependency, it will be added after the three packs slf4j-api-1.6.1.jar, slf4j-log4j12-1.7.2.jar, log4j-1.2.17.jar  
   <dependency>  
<groupId>org.slf4j</groupId>  
<artifactId>slf4j-log4j12</artifactId>  
   <version>1.7.2</version>  
   </dependency>
Configuration log4j.xml or log4j.properties file in src / main / resources
  - does not necessarily need 4.private static final Logger logger = LoggerFactory.getLogger (MINAServer.class);  
   The path allocation of resources in pom.xml is to load the resource file pom.xml while loading the package.
   
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<resources>  
           <resource>  
               <directory>src/main/resources/</directory>  
               <filtering>true</filtering>  
               <includes>  
                   <include>**/*.properties</include> 
               </includes>  
           </resource>  
        </resources>  
</configuration>
</plugin>
   
     6. In web.xml, provided by the profile Sprng loaded position Log4j
<!-- psj -->
<! - set by Sprng loaded Log4j configuration file locations - >>
<!-- <context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
  Spring refresh interval Log4j configuration file change, in milliseconds
  <context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
  </context-param>
  <listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener> -->

  <!-- psj -->




log4j.properties configuration file attributes:



. 8 = UTF-log4j.appender.encoding
# define the output level
# Log4j.rootLogger = ERROR, the ERRORLOG
Log4j.rootLogger = the INFO, the CONSOLE, the DEBUG, APPLOG, ERROR, the ERRORLOG, stdout


# Log output: console output

log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender tells that
log4j.appender.CONSOLE.Target the System.out =
  # layout format designated
log4j.appender.CONSOLE.layout = org.apache.log4j .PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern% D = {the mM-dd-YYYY HH: mm:% SS} -5p [% T]% C% X -% m% n-

######## ###########
# APPLOG output to a log file, level  
###################
log4j.appender.APPLOG = org.apache.log4j. DailyRollingFileAppender
log4j.appender.APPLOG.Append to true =
log4j.appender.APPLOG.DatePattern = '_' yyyyMMdd'.log '
log4j.appender.APPLOG.layout = Org.apache.log4j.PatternLayout
log4j.appender.APPLOG.layout.ConversionPattern =% d {yyyy-mM- dd HH: mm: ss}% -5p [% t]% c% x -% m% n
log4j.appender.APPLOG.File=/var/aicpay/logs/aicpay/access/AppAccessLog
log4j.appender.APPLOG.MaxBackupIndex=1 
log4j.appender.APPLOG.MaxFileSize=50000KB
###################
# ERRORLOG 输出到日志文件,输出级别为error级别的日志
###################
log4j.appender.ERRORLOG=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ERRORLOG.Threshold=ERROR
log4j.appender.ERRORLOG.Append=true
log4j.appender.ERRORLOG.DatePattern='_'yyyyMMdd'.log'
log4j.appender.ERRORLOG.layout=org.apache.log4j.PatternLayout
log4j.appender.ERRORLOG.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c %x - %m%n
log4j.appender.ERRORLOG.File=/var/aicpay/logs/aicpay/error/AppErrorLog
= 1 log4j.appender.ERRORLOG.MaxBackupIndex 
log4j.appender.ERRORLOG.MaxFileSize = 50000KB
### \ u663e \ u793aSQL \ u8bed \ u53e5 \ u90e8 \ u5206
# MyBatis logging the Configuration ...
log4j.logger.com.yonche the TRACE =    / / this place is more important, which packages need to print sql statement, according to his own adjustment package        com.yonche is the package name of the project 

# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

#打印sql 

### mybatis loggers ###
log4j.logger.com.ibatis=DEBUG,stdout
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG,stdout
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG,stdout
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG,stdout
# sql loggers
log4j.logger.java.sql.Connection=DEBUG,stdout
log4j.logger.java.sql.Statement=DEBUG,stdout
log4j.logger.java.sql.PreparedStatement=DEBUG,stdout
log4j.logger.java.sql.ResultSet=DEBUG,stdout 




  

Guess you like

Origin blog.csdn.net/panshoujia/article/details/78502268