Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

logback-janino-fragment is missing imports for ch.qos.logback.classic and slf4j #28

Open
chrisrueger opened this issue Nov 8, 2019 · 1 comment

Comments

@chrisrueger
Copy link

chrisrueger commented Nov 8, 2019

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 &amp;&amp; "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
@chrisrueger chrisrueger changed the title logback-janino-fragment is missing : A class 'ch.qos.logback.classic.Level' could not be found (because logback-janino-fragment is not importing logback.classic but just logback.core) logback-janino-fragment is missing imports for ch.qos.logback.classic and slf4j Nov 8, 2019
chrisrueger added a commit to chrisrueger/logback-contrib that referenced this issue Feb 2, 2020
* replaced Require-Bundle with DynamicImport-Package
* to allow janino-fragment see classes in ch.qos.logback.classic  (instead of just ch.qos.logback.core): e.g. ch.qos.logback.classic.Level 
* also added org.slf4j which is also required to be visible and is currently missing
* needed in OSGI environments
* see qos-ch#28 for details
* this also fixes the change request in qos-ch#22
chrisrueger added a commit to chrisrueger/logback-contrib that referenced this issue Feb 2, 2020
@austek
Copy link

austek commented Mar 30, 2020

What's the outlook on for fix on this issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants