Logback将日志存入mySQL中的问题?报错-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

Logback将日志存入mySQL中的问题?报错

爱吃鱼的程序员 2020-06-08 14:54:20 349

logback 版本 1.1.11 配置如下

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

	<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
		<encoder charset="UTF-8">
			<!-- 显示毫秒数 <pattern>%d{HH🇲🇲ss.SSS} [%thread] %-5level %logger - %msg%n</pattern> -->
			<pattern>%d{yyyy-MM-dd} %d{HH🇲🇲ss} %-5level [%thread] %logger -
				%msg%n</pattern>
		</encoder>
	</appender>
	<appender name="RollingFile"
		class="ch.qos.logback.core.rolling.RollingFileAppender">

		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>INFO</level>
		</filter>

		<!-- 可让每天产生一个日志文件,最多 10 个,自动回滚 -->
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<fileNamePattern>${user.dir}/logs/log-%d{yyyy-MM-dd}.log
			</fileNamePattern>
			<maxHistory>60</maxHistory>
		</rollingPolicy>
		<!-- 可让每天产生一个日志文件,最多 10 个,自动回滚 -->
		<rollingPolicy name="TAIPING"
			class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<fileNamePattern>${user.dir}/logs/log-%d{yyyy-MM-dd}.log
			</fileNamePattern>
			<maxHistory>60</maxHistory>
		</rollingPolicy>

		<encoder>
			<pattern>%d{HH🇲🇲ss.SSS} [%thread] %-5level %logger - %msg%n
			</pattern>
		</encoder>
	</appender>

	<!-- 将日志写入数据库 -->
	<appender name="MYSQL" class="ch.qos.logback.classic.db.DBAppender">
		<connectionSource
			class="ch.qos.logback.core.db.DriverManagerConnectionSource">
			<dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
				<driverClass>net.sf.log4jdbc.DriverSpy</driverClass>
				<url>jdbc:log4jdbc:mysql://127.0.0.1:3306/testdb</url>
				<user>root</user>
				<password>root</password>
				<sqlDialect class="ch.qos.logback.core.db.dialect.MySQLDialect" />
			</dataSource>
		</connectionSource>
	</appender>
	<!-- 输出到控制台和文件,可定义更多的 Appender -->
	<root level="INFO">
		<appender-ref ref="stdout" />
		<appender-ref ref="RollingFile" />
		<appender-ref ref="MYSQL" />
	</root>
</configuration>

项目启动就报错

java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.spi.Interpreter@43:66 - no applicable action for [dataSource], current ElementPath  is [[configuration][appender][connectionSource][dataSource]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@48:71 - no applicable action for [sqlDialect], current ElementPath  is [[configuration][appender][connectionSource][dataSource][sqlDialect]]
ERROR in ch.qos.logback.core.db.DriverManagerConnectionSource@4c371370 - Could not load JDBC driver class: net.sf.log4jdbc.DriverSpy java.lang.ClassNotFoundException: net.sf.log4jdbc.DriverSpy
ERROR in ch.qos.logback.core.joran.spi.Interpreter@51:13 - RuntimeException in Action for tag [appender] java.lang.IllegalStateException: DBAppender cannot function if the JDBC driver does not support getGeneratedKeys method *and* without a specific SQL dialect
	at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162)
	at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
	at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:56)
	at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:115)
	at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:308)
	at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276)
	at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
	at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:336)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)

求解这是什么问题跪求

云服务器登录 云服务器设置
分享到
取消 提交回答
全部回答(1)
  • 爱吃鱼的程序员
    2020-06-08 18:01:27

    改好了分享给大家

    <appendername="db-classic-oracle"class="ch.qos.logback.classic.db.DBAppender"><connectionSourceclass="ch.qos.logback.core.db.DriverManagerConnectionSource"><driverClass>com.mysql.jdbc.Driver</driverClass><url>jdbc:mysql://127.0.0.1:3306/datebaseName</url><user>root</user><password>root</password></connectionSource></appender>
    BEGIN;DROPTABLEIFEXISTSlogging_event_property;DROPTABLEIFEXISTSlogging_event_exception;DROPTABLEIFEXISTSlogging_event;COMMIT;BEGIN;CREATETABLElogging_event(timestmpBIGINTNOTNULL,formatted_messageTEXTNOTNULL,logger_nameVARCHAR(254)NOTNULL,level_stringVARCHAR(254)NOTNULL,thread_nameVARCHAR(254),reference_flagSMALLINT,arg0VARCHAR(254),arg1VARCHAR(254),arg2VARCHAR(254),arg3VARCHAR(254),caller_filenameVARCHAR(254)NOTNULL,caller_classVARCHAR(254)NOTNULL,caller_methodVARCHAR(254)NOTNULL,caller_lineCHAR(4)NOTNULL,event_idBIGINTNOTNULLAUTO_INCREMENTPRIMARYKEY);COMMIT;BEGIN;CREATETABLElogging_event_property(event_idBIGINTNOTNULL,mapped_keyVARCHAR(254)NOTNULL,mapped_valueTEXT,PRIMARYKEY(event_id,mapped_key),FOREIGNKEY(event_id)REFERENCESlogging_event(event_id));COMMIT;BEGIN;CREATETABLElogging_event_exception(event_idBIGINTNOTNULL,iSMALLINTNOTNULL,trace_lineVARCHAR(254)NOTNULL,PRIMARYKEY(event_id,i),FOREIGNKEY(event_id)REFERENCESlogging_event(event_id));COMMIT;

     

    0 0
数据库
使用钉钉扫一扫加入圈子
+ 订阅

分享数据库前沿,解构实战干货,推动数据库技术变革

相似问题
最新问题
推荐课程