使用mysql数据库,先创建表:
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
(
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),
caller_filename VARCHAR(254) NOT NULL,
caller_class VARCHAR(254) NOT NULL,
caller_method VARCHAR(254) NOT NULL,
caller_line CHAR(4) NOT NULL,
event_id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY
);
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;
因为要配置数据源,所以先在pom文件中加入依赖:
commons-dbcp
commons-dbcp
1.4
logback.xml配置
%d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} [%thread] %-5level %logger{36} - %msg%n
logs/error.log
logs/error/error-%d{yyyy-MM-dd}.%i.log.gz
30
100MB
%d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} [%thread] %-5level %logger{35} - %msg%n
ERROR
ACCEPT
DENY
logs/warn.log
logs/warn/warn-%d{yyyy-MM-dd}.%i.log.gz
30
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
100MB
%d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} [%thread] %-5level %logger{35} - %msg%n
WARN
ACCEPT
DENY
logs/info.log
logs/info/info-%d{yyyy-MM-dd}.%i.log.gz
30
100MB
%d{yyyy-MM-dd HH:mm:ss.SSS} ${PID} [%thread] %-5level %logger{35} - %msg%n
com.mysql.jdbc.Driver
jdbc:mysql://127.0.0.1:3306/mgr2.1?characterEncoding=UTF-8
root
root
启动应用程序就可以看到数据库里面的日志了