Logback DB appender无法使用Spring Boot

时间:2015-12-09 12:50:21

标签: spring spring-boot slf4j logback

我正在使用弹簧启动的logback。 我配置了logback.xml但是日志数据没有插入到db中。 它按照控制台读取DB appender属性。 请帮帮我。

 

    <?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<include resource="org/springframework/boot/logging/logback/basic.xml"/>
	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<layout class="ch.qos.logback.classic.PatternLayout">
			<Pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
			</Pattern>
		</layout>
	</appender>

	
	<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
		<connectionSource
			class="ch.qos.logback.core.db.DriverManagerConnectionSource">
			<driverClass>org.mariadb.jdbc.Driver</driverClass>
			<url>jdbc:mariadb://localhost:3306/twitter</url>
			<user>root</user>
			<password>*****</password>
		</connectionSource>
	</appender>
	<root level="INFO">
		<appender-ref ref="STDOUT" />
		<appender-ref ref="DB" />
	</root>

</configuration>

控制台日志如下:

18:50:01,920 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/D:/git/apache-tomcat-7.0.42/webapps/api-0.0.1-SNAPSHOT/WEB-INF/classes/logback.xml]
18:50:01,955 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
18:50:01,965 |-WARN in ch.qos.logback.core.joran.action.IncludeAction - Could not find resource corresponding to [org/springframework/boot/logging/logback/basic.xml]
18:50:01,965 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
18:50:01,967 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
18:50:02,011 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - This appender no longer admits a layout as a sub-component, set an encoder instead.
18:50:02,011 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - To ensure compatibility, wrapping your layout in LayoutWrappingEncoder.
18:50:02,011 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - See also http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for details
18:50:02,011 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.db.DBAppender]
18:50:02,015 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [DB]
18:50:02,057 |-INFO in ch.qos.logback.core.db.DriverManagerConnectionSource@e8757ef - Driver name=MariaDB connector/J
18:50:02,057 |-INFO in ch.qos.logback.core.db.DriverManagerConnectionSource@e8757ef - Driver version=1.2.3
18:50:02,057 |-INFO in ch.qos.logback.core.db.DriverManagerConnectionSource@e8757ef - supportsGetGeneratedKeys=true
18:50:02,060 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to ERROR
18:50:02,060 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
18:50:02,061 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [DB] to Logger[ROOT]
18:50:02,061 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
18:50:02,062 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@20e21368 - Registering current configuration as safe fallback point

1 个答案:

答案 0 :(得分:1)

检查更新的logback数据库表或night。 MySql架构位置:logback-classic-X.X.X.jar \ ch \ qos \ logback \ classic \ db \ script * .sql