gpt4 book ai didi

mysql - Logback DBAppender 不记录日志

转载 作者:行者123 更新时间:2023-11-30 00:13:08 27 4
gpt4 key购买 nike

尝试将 DBAppender 与 logback-access-1.1.2 一起使用。使用 DriverManagerConnectionSource 的配置。

我的程序运行,但logging_event表中没有输出,尽管有输出到控制台。

这是 logback.xml 片段:

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</encoder>
</appender>


<appender name="DB" class="ch.qos.logback.access.db.DBAppender">
<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
<debug>true</debug>
<driverClass>com.mysql.jdbc.Driver</driverClass>
<url>jdbc:mysql://10.0.0.32:3306/mydb</url>
<user>user</user>
<password>password</password>
</connectionSource>
<insertHeaders>true</insertHeaders>
</appender>


<logger name="com.rimerosolutions.gorm" level="INFO"/>
<logger name="org.steinmetz.mypkg" level="DEBUG"/>
<logger name="ch.qos.logback" level="DEBUG"/>

<root level="WARN">
<appender-ref ref="DB" />
<appender-ref ref="STDOUT" />
</root>

这几乎直接来自 logback 手册。可以通过 mysql 客户端通过命令行使用这些凭证来访问数据库。然后,还可以使用这些凭据以编程方式使用数据库。

使用 DriverManagerConnectionSource 和 DataSourceConnectionSource 之间有什么区别?

编辑:

我将调试添加到文件顶部的配置中。现在我在控制台输出中看到以下内容:

19:05:08,384 |-ERROR in ch.qos.logback.access.db.DBAppender[DB] - problem appending event java.lang.ClassCastException: ch.qos.logback.classic.spi.LoggingEvent cannot be cast to ch.qos.logback.access.spi.IAccessEvent
at java.lang.ClassCastException: ch.qos.logback.classic.spi.LoggingEvent cannot be cast to ch.qos.logback.access.spi.IAccessEvent
at at ch.qos.logback.access.db.DBAppender.subAppend(DBAppender.java:36)
at at ch.qos.logback.core.db.DBAppenderBase.append(DBAppenderBase.java:108)
at at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:88)
at at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:48)
at at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:273)
at at ch.qos.logback.classic.Logger.callAppenders(Logger.java:260)
at at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:442)
at at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:396)
at at ch.qos.logback.classic.Logger.info(Logger.java:600)
at at org.slf4j.Logger$info.call(Unknown Source)
at at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at at org.steinmetz.bitcointools.aws.TransactionsGroupProcessor$_processEntryGroups_closure1.doCall(TransactionsGroupProcessor.groovy:37)
at at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at at java.lang.reflect.Method.invoke(Method.java:597)
at at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1082)
at at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1106)
at at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:906)
at at groovy.lang.Closure.call(Closure.java:412)
at at groovy.lang.Closure.call(Closure.java:425)
at at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1326)
at at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1298)
at at org.codehaus.groovy.runtime.dgm$148.invoke(Unknown Source)
at at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
at at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
at at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at at org.steinmetz.mypkg.TransactionsGroupProcessor.processEntryGroups(TransactionsGroupProcessor.groovy:33)
at at org.steinmetz.mypkg.TransactionsGroupProcessor$processEntryGroups.call(Unknown Source)
at at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
at at org.steinmetz.mypkg.myapp.main(myapp.groovy:37)
at at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at at java.lang.reflect.Method.invoke(Method.java:597)
at at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

这实际上是某种类型的错误吗?我通过 Gradle 在我的依赖项中同时拥有 logback-classic:1.1.2 和 log back-access:1.1.2 。事件类型似乎不应该以这种方式不兼容。

最佳答案

好的,找到问题了,是appender类的配置错误。

更改此行

<appender name="DB" class="ch.qos.logback.access.db.DBAppender">

<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">

有一个关于此问题的邮件列表主题:http://logback.10977.n7.nabble.com/DBAppender-issue-td811.html

我不知道从哪里获得使用其他类名的代码,但我相信一些代码示例包含该内容。

关于mysql - Logback DBAppender 不记录日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23879829/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com