0

I've been trying to set an logback filter in my Eclipse Equinox RT application as follows:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<configuration debug="true">
    <appender name="myappender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>./logs/myapp.log</file>

        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>./logs/myapp_%i.log</fileNamePattern>
            <minIndex>1</minIndex>
            <maxIndex>10</maxIndex>
        </rollingPolicy>

        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>10MB</maxFileSize>
        </triggeringPolicy>
        
        <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
            <evaluator>
                <expression>return message.contains("buy: foo") || message.contains("sell: bar");</expression>
            </evaluator>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>

        <encoder>
            <pattern>%d{dd/MM/yyyy HH:mm:ss} | %-5level | %msg%n%ex{short}</pattern>
        </encoder>
    </appender>
    <root level="ALL">
        <appender-ref ref="myappender"/>
    </root>
</configuration>

And I have this configurations in a gradle subproject, which I'll call 'osgi-log', for reference purposes.

plugins {
    id 'java-library' version '1.0.0'
}

group 'myapp'
version '2.0.0'

dependencies {
    api group: 'org.slf4j', name: 'slf4j-api', version: '2.0.5'

    implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.5'
    implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.3.5'
    implementation group: 'org.codehaus.janino', name: 'janino', version: '3.1.12'

    implementation group: 'org.ow2.asm', name: 'asm', version: '5.2'
    implementation group: 'org.ow2.asm', name: 'asm-commons', version: '5.2'
    implementation group: 'org.ow2.asm', name: 'asm-util', version: '5.2'
    implementation group: 'org.apache.aries.spifly', name: 'org.apache.aries.spifly.dynamic.bundle', version: '1.3.5'
}

The 'osgi-log' is being set in other gradle subprojects like this:

dependencies 
{
    implementation group: 'myapp', name: 'osgi-log'
}

When I run the application, I'm getting the following exception:

ERROR in ch.qos.logback.classic.boolex.JaninoEventEvaluator@75243b22 - Could not start evaluator with expression [return message.contains("buy: foo") || message.contains("sell: bar");] org.codehaus.commons.compiler.CompileException: Line 1, Column 1: A class "ch.qos.logback.classic.Level" could not be found
        at org.codehaus.commons.compiler.CompileException: Line 1, Column 1: A class "ch.qos.logback.classic.Level" could not be found

Observations:

  • Log works as expected if I remove the filter. The exception is being thrown only then I add the filter.
  • The configuration file is being loaded through system environment -Dlogback.configurationFile=file:logback.xml.
  • It is a java 8 application.

Any other suggestions or simplier way to achieve the same result, would be welcome -- I want to filter the events and only register those who match some group of characters.

Plus:

I would appreciate if someone could help me understand why can't Apache SpiFly doesn't resolve dynamically all the dependencies for Janino's implentation?

3
  • not able to reproduce this issue using provided dependency, anyway to provide a minimal reproducible example? Commented Nov 12, 2024 at 11:51
  • Now that you commented, I feel I missed important informations, I'll add it now. Commented Nov 12, 2024 at 12:53
  • I am suspecting this is not an osgi-related issue. Seems to be versions dependency compatibility between logback and janino. Commented Nov 12, 2024 at 15:10

1 Answer 1

0

I actually found the fix for it.

It seems to be a known issue in Janino's dependency end.

In order to make this work, it is need to adjust the MANIFEST.MF in both janino and commons-compiler adding the following line:

DynamicImport-Package: ch.qos.logback.*,org.slf4j

References:

https://github.com/qos-ch/logback-contrib/pull/29/files

https://github.com/qos-ch/logback-contrib/issues/28

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.