然后就是配置了。
首先是报错的配置,也是网上找资料别人给的配置……
复制代码
<!-- 将日志存储到oracle数据库中 -->
<appender name="db-classic-oracle" class="ch.qos.logback.classic.db.DBAppender">
<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
<dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
<driverClassName>oracle.jdbc.driver.OracleDriver</driverClassName>
<url>jdbc:oracle:thin:@localhost:1521:ZYD</url>
<user>scott</user>
<password>tiger</password>
</dataSource>
</connectionSource>
</appender>
复制代码
运行一下,你会发现会报这个错误:DBAppender cannot function if the JDBC driver does not support getGeneratedKeys method *and* without a specific SQL dialect
然后把气冲冲的加上了方言……
复制代码
<!-- 将日志存储到oracle数据库中 -->
<appender name="db-classic-oracle" class="ch.qos.logback.classic.db.DBAppender">
<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
<dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
<driverClassName>oracle.jdbc.driver.OracleDriver</driverClassName>
<url>jdbc:oracle:thin:@localhost:1521:ZYD</url>
<user>scott</user>
<password>tiger</password>
<sqlDialect class="ch.qos.logback.core.db.dialect.OracleDialect" />
</dataSource>
</connectionSource>
</appender>
复制代码
结果还是不对!
最后跑去Stack OwerFlow网站看了一下那帮外国程序员是怎么解决的,终于在看了几个帮助之后
发现了……
<driverClassName>oracle.jdbc.driver.OracleDriver</driverClassName>
原来还有它的错,正确的应该是
复制代码
<!-- 将日志存储到oracle数据库中 -->
<appender name="db-classic-oracle" class="ch.qos.logback.classic.db.DBAppender">
<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
<dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
<driverClass>oracle.jdbc.driver.OracleDriver</driverClass>
<url>jdbc:oracle:thin:@localhost:1521:ZYD</url>
<user>scott</user>
<password>tiger</password>
<sqlDialect class="ch.qos.logback.core.db.dialect.OracleDialect" />
</dataSource>
</connectionSource>
</appender>
复制代码
再试一下,终于成功了!
、引入logback pom配置[html] view plain copy
<logback.version>1.0.13</logback.version>
[html] view plain copy
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
2、配置logback.xml
新增一个event的appender名字叫event,新加一个logger,将其apender指定为event,指定其level为INFO,additivity="false"这个最重要,指定日志不向上一级输入。之后,在类cn.company.bau.desktop.composite.EventRealTimeComposite中,就可以用logger.info("xxx")输出日志,日志会记录到event.log中,并按策略生成,以供分析
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)