logback-janino-fragment is missing imports for ch.qos.logback.classic and slf4j
chrisrueger opened this issue · 1 comments
In our Apache Felix Logback based OSGI Environment we get the following error when using an expression in an EvaluatorFilter:
Could not start evaluator with expression [mdc != null && "true".equals(mdc.get("enableLogHttpTraffic"))] org.codehaus.commons.compiler.CompileException: Line 1, Column 7: A class 'ch.qos.logback.classic.Level' could not be found
Our appender:
<appender name="HTTP_LOG_CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator name="httpEvaluator" class="ch.qos.logback.classic.boolex.JaninoEventEvaluator"> <!-- defaults to type ch.qos.logback.classic.boolex.JaninoEventEvaluator -->
<expression>mdc != null && "true".equals(mdc.get("enableLogHttp"))</expression>
</evaluator>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%X{client} | %-4date | %msg%n</Pattern>
</layout>
</appender>
Reason
We found out that janino-fragment only does a
Require-Bundle: ch.qos.logback.core
in MANIFEST.MF
So it cannot see the class ch.qos.logback.classic.Level which lives in ch.qos.logback.classic
The easiest thing would be to extend:
Require-Bundle: ch.qos.logback.core,\
ch.qos.logback.classic
We tested this and it fixes the problem, but then a new but similar error appeared
Could not start evaluator with expression [mdc != null && "true".equals(mdc.get("enableLogHttp"))] org.codehaus.janino.JaninoRuntimeException: Cannot load class 'org.slf4j.Marker' through the parent loader
at org.codehaus.janino.JaninoRuntimeException: Cannot load class 'org.slf4j.Marker' through the parent loader
at at org.codehaus.janino.SimpleCompiler$1.getDelegate(SimpleCompiler.java:325)
at at org.codehaus.janino.SimpleCompiler$1.accept(SimpleCompiler.java:301)
at at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:5660)
This could be fixed by adding
Import-Package: org.slf4j
to MANIFEST.MF
Summary
Maybe it should be fixed together with #22 which asks to replace the Require-Bundle
with DynamicImport-Package
I tested this as well and it works and fixes also my problem when MANIFEST.MF is modified like this:
Modify MANIFEST.MF like this:
remove
Require-Bundle: ch.qos.logback.core
and add
DynamicImport-Package: ch.qos.logback.*,\
org.slf4j
What's the outlook on for fix on this issue?