logback怎么异步日志到oracle数据库中
2017-06-12
展开全部
首先是下载所需要的包,然后在\logback-1.1.2\logback-classic\src\main\java\ch\qos\logback\classic\db\script下你能看到创建日志所需要的的建表脚本
然后就是配置了。
首先是报错的配置,也是网上找资料别人给的配置……
复制代码
<!-- 将日志存储到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>
复制代码
再试一下,终于成功了!
然后就是配置了。
首先是报错的配置,也是网上找资料别人给的配置……
复制代码
<!-- 将日志存储到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>
复制代码
再试一下,终于成功了!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询