A custom filter is added to the logback.xml, project start exception

A custom filter is added to the logback.xml as follows:

<appender name="iot" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="magic.extension.PatternLogbackFilter">
            <logPattern>magic.core.service.iot\..*</logPattern>
        </filter>

Exception stack:

at java.lang.ClassNotFoundException: magic.extension.PatternLogbackFilter
	at 	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at 	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at 	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	at 	at ch.qos.logback.core.util.Loader.loadClass(Loader.java:120)
	at 	at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.begin(NestedComplexPropertyIA.java:102)
	at 	at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:269)
	at 	at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:145)
	at 	at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:128)
	at 	at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
	at 	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
	at 	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
	at 	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
	at 	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
	at 	at com.haulmont.cuba.core.sys.logging.LogbackConfigurator.configureByResource(LogbackConfigurator.java:74)
	at 	at com.haulmont.cuba.core.sys.logging.LogbackConfigurator.configure(LogbackConfigurator.java:49)

This class file is certain to exist

it may exist, but is it it the correct place?

where did you define the filter? Is it your implementation or 3rd party framework? Where is it being referenced?

did you put a dependency in core but using it in web for example?

It’s a class implemented by myself, which is in the Tomcat / webapps / xxx/ WEB-INF / lib directory. When I use the classes in cuba-web-7.2.11.jar, the same error occurs.

Is there any solution?

Hi,
I’m afraid that you need to have your class to be located in a shared library (deployed to tomcat/shared/lib) in order to be able to use it in logback.xml.

So you need to implement your filter in a separate Java library, not depending on CUBA.
Then add this library as dependency to your main project.
You will be able to reference this filter class from your project’s code, but not visa versa.

Oh, a sad conclusion