The android implementation of logback appears to be missing the DBAppender class.
Here's my relevant logback appender config, located in assets/logback.xml.
<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
<driverClass>com.mysql.jdbc.Driver</driverClass>
<url>jdbc:mysql://10.2.2.222:3306/logback</url>
<user>username</user>
<password>thepassword</password>
</connectionSource>
</appender>
And gradle:
implementation 'org.slf4j:slf4j-api:1.7.25'
implementation 'com.github.tony19:logback-android:1.1.1-12'
and the resulting error in my logcat:
20:40:50,225 |-ERROR in ch.qos.logback.core.joran.action.AppenderAction -
Could not create an Appender of type [ch.qos.logback.classic.db.DBAppender].
ch.qos.logback.core.util.DynamicClassLoadingException:
Failed to instantiate type ch.qos.logback.classic.db.DBAppender
at ch.qos.logback.core.util.DynamicClassLoadingException:
Failed to instantiate type ch.qos.logback.classic.db.DBAppender
and
Caused by: ch.qos.logback.core.util.DynamicClassLoadingException:
Failed to instantiate type ch.qos.logback.classic.db.DBAppender
and
Caused by: java.lang.ClassNotFoundException:
Didn't find class "ch.qos.logback.classic.db.DBAppender"
Logback is properly working otherwise, if I comment out the database stuff and just have it log to a file, it instantiates correctly and generates text in the log file.
I've found examples of people using the DBAppender, but haven't found any that appear to be android based.
ps: I've also tried the other option, DataSourceConnectionSource (as opposed to the shown DriverManagerConnectionSource) but it actually uses the same appender, and so has the same error as a result. I also can't find any references to to DBAppender in the github files.
logback-android
currently does not support DBAppender
, and there are no firm plans to carry over that feature. The only database appender supported is SQLiteAppender
.
It should be relatively simple to pull DBAppender
's relevant source from logback
into its own library that could be used in logback-android
. For a future major release, I plan on splitting out several built-in appenders in this way to minimize the library size.