I use a logback file to store logs in an array so that I can read them in the UI.
Unfortunately I have problems with this, because when I regenerate / update the database a ClassNotFoundException is thrown by Liquibase.
<configuration>
<!-- UNCOMMENT IF YOU RECREATE DATABASE -->
<appender name="MEMORY" class="de.bytestore.hostinger.listener.InMemoryAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="MEMORY"/>
</root>
</configuration>
Appender Class:
package de.bytestore.hostinger.listener;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.UnsynchronizedAppenderBase;
import lombok.Getter;
import java.util.ArrayList;
import java.util.concurrent.LinkedBlockingDeque;
public class InMemoryAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
@Getter
static final LinkedBlockingDeque<ILoggingEvent> events = new LinkedBlockingDeque<>(1024);
static final ArrayList<InMemoryListener> listeners = new ArrayList<>();
/**
* Attaches a given InMemoryListener to the listeners list.
* The attached listener will receive events and updates.
*
* @param listenerIO The InMemoryListener to attach.
*/
public static void attach(InMemoryListener listenerIO) {
listeners.add(listenerIO);
}
/**
* Detaches a given InMemoryListener from the listeners list.
* The detached listener will no longer receive events and updates.
*
* @param listenerIO The InMemoryListener to detach.
*/
public static void detach(InMemoryListener listenerIO) {
listeners.remove(listenerIO);
}
/**
* Appends a logging event to the list of events.
* If the list exceeds the size limit of 1024, the oldest event will be removed.
*
* @param event the logging event to append
*/
@Override
protected void append(ILoggingEvent event) {
// Print Output.
System.out.println(event.getFormattedMessage());
// Remove old Logs.
if (events.size() > 1024) {
events.removeFirst();
}
// Add last Log.
events.addLast(event);
// Sometimes it's holding Thread in this line... @todo
// Print Message for all Listeners.
listeners.forEach(listener -> {
listener.onLog(event);
});
}
}
12:33:50,822 |-ERROR in ch.qos.logback.core.model.processor.AppenderModelHandler - Could not create an Appender of type [de.bytestore.hostinger.listener.InMemoryAppender]. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type de.bytestore.hostinger.listener.InMemoryAppender
at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type de.bytestore.hostinger.listener.InMemoryAppender
at at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:69)
at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:44)
at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:33)
at at ch.qos.logback.core.model.processor.AppenderModelHandler.handle(AppenderModelHandler.java:67)
at at ch.qos.logback.core.model.processor.DefaultProcessor.secondPhaseTraverse(DefaultProcessor.java:241)
at at ch.qos.logback.core.model.processor.DefaultProcessor.secondPhaseTraverse(DefaultProcessor.java:253)
at at ch.qos.logback.core.model.processor.DefaultProcessor.traversalLoop(DefaultProcessor.java:90)
at at ch.qos.logback.core.model.processor.DefaultProcessor.process(DefaultProcessor.java:106)
at at ch.qos.logback.core.joran.GenericXMLConfigurator.processModel(GenericXMLConfigurator.java:208)
at at ch.qos.logback.core.joran.GenericXMLConfigurator.doConfigure(GenericXMLConfigurator.java:170)
at at ch.qos.logback.core.joran.GenericXMLConfigurator.doConfigure(GenericXMLConfigurator.java:122)
at at ch.qos.logback.core.joran.GenericXMLConfigurator.doConfigure(GenericXMLConfigurator.java:65)
at at ch.qos.logback.classic.util.DefaultJoranConfigurator.configureByResource(DefaultJoranConfigurator.java:68)
at at ch.qos.logback.classic.util.DefaultJoranConfigurator.configure(DefaultJoranConfigurator.java:35)
at at ch.qos.logback.classic.util.ContextInitializer.invokeConfigure(ContextInitializer.java:122)
at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:97)
at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:65)
at at ch.qos.logback.classic.spi.LogbackServiceProvider.initializeLoggerContext(LogbackServiceProvider.java:52)
at at ch.qos.logback.classic.spi.LogbackServiceProvider.initialize(LogbackServiceProvider.java:41)
at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:195)
at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:182)
at at org.slf4j.LoggerFactory.getProvider(LoggerFactory.java:490)
at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:476)
at at org.apache.logging.slf4j.SLF4JLogger.<clinit>(SLF4JLogger.java:39)
at at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:36)
at at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:666)
at at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at at org.hsqldb.lib.FrameworkLogger.<init>(Unknown Source)
at at org.hsqldb.lib.FrameworkLogger.getLog(Unknown Source)
at at org.hsqldb.lib.FrameworkLogger.getLog(Unknown Source)
at at org.hsqldb.persist.Logger.getEventLogger(Unknown Source)
at at org.hsqldb.persist.Logger.logDetailEvent(Unknown Source)
at at org.hsqldb.persist.Log.closeLog(Unknown Source)
at at org.hsqldb.persist.Log.close(Unknown Source)
at at org.hsqldb.persist.Logger.close(Unknown Source)
at at org.hsqldb.Database.close(Unknown Source)
at at org.hsqldb.Database.closeIfLast(Unknown Source)
at at org.hsqldb.Session.close(Unknown Source)
at at org.hsqldb.jdbc.JDBCConnection.close(Unknown Source)
at at liquibase.database.jvm.JdbcConnection.close(JdbcConnection.java:262)
at at liquibase.database.AbstractJdbcDatabase.close(AbstractJdbcDatabase.java:1209)
at at liquibase.integration.commandline.Main.doMigration(Main.java:1923)
at at liquibase.integration.commandline.Main$1.lambda$run$0(Main.java:415)
at at liquibase.Scope.lambda$child$0(Scope.java:187)
at at liquibase.Scope.child(Scope.java:196)
at at liquibase.Scope.child(Scope.java:186)
at at liquibase.Scope.child(Scope.java:165)
at at liquibase.integration.commandline.Main$1.run(Main.java:414)
at at liquibase.integration.commandline.Main$1.run(Main.java:231)
at at liquibase.Scope.child(Scope.java:196)
at at liquibase.Scope.child(Scope.java:172)
at at liquibase.integration.commandline.Main.run(Main.java:231)
at at liquibase.integration.commandline.Main.main(Main.java:173)
Caused by: java.lang.ClassNotFoundException: de.bytestore.hostinger.listener.InMemoryAppender
at at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:56)
at ... 53 common frames omitted
12:33:50,822 |-ERROR in ch.qos.logback.core.model.processor.DefaultProcessor@46185a1b - Failed to traverse model appender ch.qos.logback.core.model.processor.ModelHandlerException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type de.bytestore.hostinger.listener.InMemoryAppender
at ch.qos.logback.core.model.processor.ModelHandlerException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type de.bytestore.hostinger.listener.InMemoryAppender
at at ch.qos.logback.core.model.processor.AppenderModelHandler.handle(AppenderModelHandler.java:75)
at at ch.qos.logback.core.model.processor.DefaultProcessor.secondPhaseTraverse(DefaultProcessor.java:241)
at at ch.qos.logback.core.model.processor.DefaultProcessor.secondPhaseTraverse(DefaultProcessor.java:253)
at at ch.qos.logback.core.model.processor.DefaultProcessor.traversalLoop(DefaultProcessor.java:90)
at at ch.qos.logback.core.model.processor.DefaultProcessor.process(DefaultProcessor.java:106)
at at ch.qos.logback.core.joran.GenericXMLConfigurator.processModel(GenericXMLConfigurator.java:208)
at at ch.qos.logback.core.joran.GenericXMLConfigurator.doConfigure(GenericXMLConfigurator.java:170)
at at ch.qos.logback.core.joran.GenericXMLConfigurator.doConfigure(GenericXMLConfigurator.java:122)
at at ch.qos.logback.core.joran.GenericXMLConfigurator.doConfigure(GenericXMLConfigurator.java:65)
at at ch.qos.logback.classic.util.DefaultJoranConfigurator.configureByResource(DefaultJoranConfigurator.java:68)
at at ch.qos.logback.classic.util.DefaultJoranConfigurator.configure(DefaultJoranConfigurator.java:35)
at at ch.qos.logback.classic.util.ContextInitializer.invokeConfigure(ContextInitializer.java:122)
at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:97)
at at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:65)
at at ch.qos.logback.classic.spi.LogbackServiceProvider.initializeLoggerContext(LogbackServiceProvider.java:52)
at at ch.qos.logback.classic.spi.LogbackServiceProvider.initialize(LogbackServiceProvider.java:41)
at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:195)
at at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:182)
at at org.slf4j.LoggerFactory.getProvider(LoggerFactory.java:490)
at at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:476)
at at org.apache.logging.slf4j.SLF4JLogger.<clinit>(SLF4JLogger.java:39)
at at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:36)
at at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:666)
at at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at at org.hsqldb.lib.FrameworkLogger.<init>(Unknown Source)
at at org.hsqldb.lib.FrameworkLogger.getLog(Unknown Source)
at at org.hsqldb.lib.FrameworkLogger.getLog(Unknown Source)
at at org.hsqldb.persist.Logger.getEventLogger(Unknown Source)
at at org.hsqldb.persist.Logger.logDetailEvent(Unknown Source)
at at org.hsqldb.persist.Log.closeLog(Unknown Source)
at at org.hsqldb.persist.Log.close(Unknown Source)
at at org.hsqldb.persist.Logger.close(Unknown Source)
at at org.hsqldb.Database.close(Unknown Source)
at at org.hsqldb.Database.closeIfLast(Unknown Source)
at at org.hsqldb.Session.close(Unknown Source)
at at org.hsqldb.jdbc.JDBCConnection.close(Unknown Source)
at at liquibase.database.jvm.JdbcConnection.close(JdbcConnection.java:262)
at at liquibase.database.AbstractJdbcDatabase.close(AbstractJdbcDatabase.java:1209)
at at liquibase.integration.commandline.Main.doMigration(Main.java:1923)
at at liquibase.integration.commandline.Main$1.lambda$run$0(Main.java:415)
at at liquibase.Scope.lambda$child$0(Scope.java:187)
at at liquibase.Scope.child(Scope.java:196)
at at liquibase.Scope.child(Scope.java:186)
at at liquibase.Scope.child(Scope.java:165)
at at liquibase.integration.commandline.Main$1.run(Main.java:414)
at at liquibase.integration.commandline.Main$1.run(Main.java:231)
at at liquibase.Scope.child(Scope.java:196)
at at liquibase.Scope.child(Scope.java:172)
at at liquibase.integration.commandline.Main.run(Main.java:231)
at at liquibase.integration.commandline.Main.main(Main.java:173)
Caused by: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type de.bytestore.hostinger.listener.InMemoryAppender
at at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:69)
at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:44)
at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:33)
at at ch.qos.logback.core.model.processor.AppenderModelHandler.handle(AppenderModelHandler.java:67)
at ... 50 common frames omitted
Caused by: java.lang.ClassNotFoundException: de.bytestore.hostinger.listener.InMemoryAppender
at at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:56)
at ... 53 common frames omitted
12:33:50,822 |-INFO in ch.qos.logback.core.model.processor.DefaultProcessor@46185a1b - End of configuration.
The error only occurs when I generate an entity or recreate the database.
If I start JMIX normally, there are no problems ;(
Is there a way to ignore the logback file in Liquibase?