springboot使用logback将日志同步到mysql

行业动态 公司新闻 案例分享 技术百科

springboot使用logback将日志同步到mysql

来源:奇站网络 浏览量:60 发布日期: 2025-03-17

<root level="INFO">      
   <appender-ref ref="MYSQL" />
</root>

<!--输出到mysql数据库的appender配置     -->
 <appender name="MYSQL" class="ch.qos.logback.classic.db.DBAppender">
     <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
         <driverClass>com.mysql.jdbc.Driver</driverClass>
         <url>jdbc:mysql://localhost:3306/my_logs?useSSL=false</url>
         <user>root</user>
         <password>root</password>
     </connectionSource>
 </appender>


use my_logs;

BEGIN;
DROP TABLE IF EXISTS logging_event_property;
DROP TABLE IF EXISTS logging_event_exception;
DROP TABLE IF EXISTS logging_event;
COMMIT;

BEGIN;
CREATE TABLE logging_event 
  (
    event_id         BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    timestmp         BIGINT NOT NULL,
    formatted_message  TEXT NOT NULL,
    logger_name       VARCHAR(254) NOT NULL,
    level_string      VARCHAR(254) NOT NULL,
    thread_name       VARCHAR(254),
    reference_flag    SMALLINT,
    arg0              VARCHAR(254),
    arg1              VARCHAR(254),
    arg2              VARCHAR(254),
    arg3              VARCHAR(254),
    arg4              VARCHAR(254),
    arg5              VARCHAR(254),
    caller_filename   VARCHAR(254) NOT NULL,
    caller_class      VARCHAR(254) NOT NULL,
    caller_method     VARCHAR(254) NOT NULL,
    caller_line       CHAR(4) NOT NULL
  );
COMMIT;


BEGIN;
CREATE TABLE logging_event_property
  (
    event_id       BIGINT NOT NULL,
    mapped_key        VARCHAR(254) NOT NULL,
    mapped_value      TEXT,
    PRIMARY KEY(event_id, mapped_key),
    FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
  );
COMMIT;


BEGIN;
CREATE TABLE logging_event_exception
  (
    event_id         BIGINT NOT NULL,
    i                SMALLINT NOT NULL,
    trace_line       VARCHAR(254) NOT NULL,
    PRIMARY KEY(event_id, i),
    FOREIGN KEY (event_id) REFERENCES logging_event(event_id)
  );
COMMIT;


标签:
下一篇

厦门奇站网络科技有限公司

如需更多服务咨询,请打给我。

133-1386-8605

厦门市集美区创业大厦

网站地图


                   扫一扫加我咨询