我一直在尝试在基于 maven 的 spring 项目上配置 p3spy 日志记录系统。但是每次我尝试以不同的方式配置 p3spy 时。我总是出错。
这是我的以下设置
我将 p6spy-2.3.0.jar、spy.properties 和 mysql-connector-java-5.1.17.jar 放在了 tomcat/lib 目录中。
tomcat/context.xml
<Resource auth="Container"
driverClassName="com.mysql.jdbc.Driver"
name="jdbc/myDataSource"
type="javax.sql.DataSource"
url="jdbc:p6spy:mysql://localhost:3306/coexi?useUnicode=true&characterEncoding=utf-8"
username="root"
password=""
maxActive="100"
maxIdle="50" />
在使用上述设置时..它给了我以下错误..
无法为连接 URL“jdbc:p6spy:mysql://localhost:3306/coexi?useUnicode=true&characterEncoding=utf-8”创建类“com.mysql.jdbc.Driver”的 JDBC 驱动程序 java.sql.SQLException:没有合适的驱动程序
在这里,我还尝试替换此资源中的一些设置。
<Resource auth="Container"
driverClassName="com.p6spy.engine.spy.P6SpyDriver"
name="jdbc/myDataSource"
type="javax.sql.DataSource"
url="jdbc:p6spy:mysql://localhost:3306/coexi?useUnicode=true&characterEncoding=utf-8"
username="root"
password=""
maxActive="100"
maxIdle="50" />
并通过使用此代码,得到以下错误:
即使第二次尝试,也无法实例化 com.p6spy.engine.logging.appender.Log4jLogger。java.lang.ClassNotFoundException: com.p6spy.engine.logging.appender.Log4jLogger
主/配置/持久性配置
@Bean
public DataSource dataSource() {
Context ctx;
try {
ctx = new InitialContext();
return (DataSource) ctx.lookup("java:comp/env/jdbc/myDataSource");
} catch (NamingException e) {
LOGGER.info("Error to find the database : \"java:comp/env/jdbc/myDataSource\".");
}
return null;
tomcat/lib/spy.properties
driverlist=com.mysql.jdbc.Driver
deregisterdrivers=true
includecategories=info, statement
excludecategories=info,debug,result,batch
logfile = /Users/coexi/Documents/spy.log
append=true
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=p6spy - %m%n
log4j.logger.p6spy=INFO,STDOUT
/main/resources/logback.xml
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<appender name="GEN_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/general.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>gen_%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<category name="com.p6spy">
<priority value="INFO" />
</category>
<logger name="org.hibernate.SQL" additivity="false" >
<level value="DEBUG" />
<appender-ref ref="SQLROLLINGFILE" />
</logger>
<logger name="org.hibernate.type" additivity="false" >
<level value="TRACE" />
<appender-ref ref="SQLROLLINGFILE" />
</logger>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
<root level="error">
<appender-ref ref="ERRORS_FILE"/>
</root>
主/资源/log4j.xml.backend
<?xml version="1.0" encoding="UTF-8" ?>
http://jakarta.apache.org/log4j/'>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="INFO" />
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<category name="com.p6spy">
<priority value="INFO" />
</category>
<logger name="org.hibernate.SQL" additivity="false" >
<level value="DEBUG" />
<appender-ref ref="SQLROLLINGFILE" />
</logger>
<logger name="org.hibernate.type" additivity="false" >
<level value="TRACE" />
<appender-ref ref="SQLROLLINGFILE" />
</logger>
<root>
<level value="INFO" />
<appender-ref ref="console" />
</root>
全栈错误。
http://pastebin.com/3LpgtPtr