当前位置:   article > 正文

logback系列之五:输出日志到数据库-DBAppender生成的表_logback配置日志直接输出到db某个表中

logback配置日志直接输出到db某个表中
需要手动添加
  1. # Logback: the reliable, generic, fast and flexible logging framework.
  2. # Copyright (C) 1999-2010, QOS.ch. All rights reserved.
  3. #
  4. # See http://logback.qos.ch/license.html for the applicable licensing
  5. # conditions.
  6. # This SQL script creates the required tables by ch.qos.logback.classic.db.DBAppender.
  7. #
  8. # It is intended for MySQL databases. It has been tested on MySQL 5.1.37
  9. # on Linux
  10. use tumorpredict;
  11. BEGIN;
  12. DROP TABLE IF EXISTS logging_event_property;
  13. DROP TABLE IF EXISTS logging_event_exception;
  14. DROP TABLE IF EXISTS logging_event;
  15. COMMIT;
  16. BEGIN;
  17. CREATE TABLE logging_event
  18. (
  19. timestmp BIGINT NOT NULL,
  20. formatted_message TEXT NOT NULL,
  21. logger_name VARCHAR(254) NOT NULL,
  22. level_string VARCHAR(254) NOT NULL,
  23. thread_name VARCHAR(254),
  24. reference_flag SMALLINT,
  25. arg0 VARCHAR(254),
  26. arg1 VARCHAR(254),
  27. arg2 VARCHAR(254),
  28. arg3 VARCHAR(254),
  29. caller_filename VARCHAR(254) NOT NULL,
  30. caller_class VARCHAR(254) NOT NULL,
  31. caller_method VARCHAR(254) NOT NULL,
  32. caller_line CHAR(4) NOT NULL,
  33. event_id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY
  34. );
  35. COMMIT;
  36. BEGIN;
  37. CREATE TABLE logging_event_property
  38. (
  39. event_id BIGINT NOT NULL,
  40. mapped_key VARCHAR(254) NOT NULL,
  41. mapped_value TEXT,
  42. PRIMARY KEY(event_id, mapped_key),
  43. FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
  44. );
  45. COMMIT;
  46. BEGIN;
  47. CREATE TABLE logging_event_exception
  48. (
  49. event_id BIGINT NOT NULL,
  50. i SMALLINT NOT NULL,
  51. trace_line VARCHAR(254) NOT NULL,
  52. PRIMARY KEY(event_id, i),
  53. FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
  54. );
  55. COMMIT;
XML详细配置
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " http://www.w3.org/2002/xmlspec/dtd/2.10/xmlspec.dtd">
  3. <configuration>
  4. <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
  5. <layout class="ch.qos.logback.classic.PatternLayout">
  6. <pattern>%-20(%d{HH:mm:ss.SSS} [%thread]) %-5level %logger{80} - %msg%n</pattern>
  7. </layout>
  8. </appender>
  9. <!--
  10. <property name="log.base" value="../logs/" /> <appender name="file"
  11. class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${log.base}.log</file> <rollingPolicy
  12. class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  13. <fileNamePattern>${log.base}.%d{yyyy-MM-dd}.log.zip</fileNamePattern> </rollingPolicy> <layout
  14. class="ch.qos.logback.classic.PatternLayout"> <pattern>%-20(%d{HH:mm:ss.SSS} [%thread]) %-5level %logger{80} -
  15. %msg%n</pattern> </layout> </appender>
  16. <appender name="db-classic-oracle" class="ch.qos.logback.classic.db.DBAppender">
  17. <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
  18. <dataSource class="org.apache.commons.dbcp.BasicDataSource">
  19. <driverClassName>oracle.jdbc.driver.OracleDriver</driverClassName>
  20. <url>jdbc:oracle:thin:@192.168.3.250:1521:devdb</url>
  21. <user>logback</user>
  22. <password>logback</password>
  23. </dataSource>
  24. </connectionSource>
  25. </appender>
  26. <appender name="db-classic-mysql" class="ch.qos.logback.classic.db.DBAppender">
  27. <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
  28. <driverClass>com.mysql.jdbc.Driver</driverClass>
  29. <url>jdbc:mysql://localhost:3306/logbackdb</url>
  30. <user>root</user>
  31. <password>qqqqqq</password>
  32. </connectionSource>
  33. </appender>
  34. <appender name="db-access" class="ch.qos.logback.access.db.DBAppender">
  35. <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
  36. <driverClass>com.mysql.jdbc.Driver</driverClass>
  37. <url>jdbc:mysql://localhost:3306/logbackdb</url>
  38. <user>root</user>
  39. <password>qqqqqq</password>
  40. </connectionSource>
  41. <insertHeaders>true</insertHeaders>
  42. </appender>
  43. -->
  44. <appender name="db-classic-mysql-pool" class="ch.qos.logback.classic.db.DBAppender">
  45. <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
  46. <dataSource class="org.apache.commons.dbcp.BasicDataSource">
  47. <driverClassName>com.mysql.jdbc.Driver</driverClassName>
  48. <url>jdbc:mysql://localhost:3306/logbackdb</url>
  49. <username>root</username>
  50. <password>qqqqqq</password>
  51. </dataSource>
  52. </connectionSource>
  53. </appender>
  54. <appender name="db-classic-oracle-pool" class="ch.qos.logback.classic.db.DBAppender">
  55. <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
  56. <dataSource class="org.apache.commons.dbcp.BasicDataSource">
  57. <driverClassName>oracle.jdbc.driver.OracleDriver</driverClassName>
  58. <url>jdbc:oracle:thin:@192.168.3.250:1521:devdb</url>
  59. <username>logback</username>
  60. <password>logback</password>
  61. </dataSource>
  62. </connectionSource>
  63. </appender>
  64. <root level="WARN">
  65. <appender-ref ref="stdout" />
  66. <appender-ref ref="db-classic-oracle-pool" />
  67. </root>
  68. </configuration>


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/312781
推荐阅读
相关标签
  

闽ICP备14008679号