0

Trying to use a DBAppender with logback-access-1.1.2. Using configuration for a DriverManagerConnectionSource.

My program runs, but no output in the logging_event table, though has output to the console.

Here is the logback.xml snippet:

<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>

This is pretty much straight out of the logback manual. The database is accessible using those credential off the command line with the mysql client. Then database is also used programmatically using those credentials.

Also what is the difference between using a DriverManagerConnectionSource and DataSourceConnectionSource ?

EDIT:

I added debug to the configuration with at the top of the file. Now I see the following in the console output:

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)

Is this actually some type of bug? I have both logback-classic:1.1.2 and log back-access:1.1.2 in my dependencies via Gradle. It doesn't seem like the the event types should be incompatible in this way.

Peter N. Steinmetz
  • 1,252
  • 1
  • 15
  • 23
  • You have the root level at "WARN", so DEBUG and INFO level logs will be suppressed. Try setting the root level to DEBUG. – GreyBeardedGeek May 27 '14 at 01:39
  • I think the specific settings for levels in the logger entries are working for those particular classes, because the proper output appears in the console. Changing the root to DEBUG produces a lot more output on the console (basically for everything) but none in the database. – Peter N. Steinmetz May 27 '14 at 01:42

1 Answers1

0

OK, found the problem, which is a configuration error in the class for the appender.

Change this line

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

to

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

There is a mailing list thread about this at http://logback.10977.n7.nabble.com/DBAppender-issue-td811.html.

I don't know where I got the code to use the other classname, but I believe some code example floating around contains that.

Peter N. Steinmetz
  • 1,252
  • 1
  • 15
  • 23