Reputation: 97
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:
-Dlogback.configurationFile=file:logback.xml
.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?
Upvotes: 0
Views: 45
Reputation: 97
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
Upvotes: 0