Logback DBAppender没有记录

时间:2014-05-27 01:33:15

标签: mysql logback appender

尝试将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)

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

1 个答案:

答案 0 :(得分:0)

好的,发现问题,这是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有一个关于此的邮件列表主题。

我不知道我在哪里获得了使用其他类名的代码,但我相信一些浮动的代码示例包含了这个。