3

I am currently trying to set up a logging facility in our Eclipse based product using SLF4J as bundles out of the Eclipse Orbit project.

I use in detail:

org.slf4j.api
ch.qos.logback.classic
ch.qos.logback.core
ch.qos.logback.slf4j

When I try to run the test cases using the SLF4J log api, in the Tycho build I get the error message

19:05:50 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
19:05:50 SLF4J: Defaulting to no-operation (NOP) logger implementation
19:05:50 SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Surefire only uses the target platform for the Eclipse product and plugin Manifest.MF files to detect the dependencies. Since ch.qos.logback.slf4j is a fragment, a direct dependency in the Manifest is not possible.

My assumption is that the fragment is not part of the runtime configuration during the test execution.

I hope my question is not too stupid, but how can I configure the environment so that the fragment is added to the runtime configuration and SLF4J can solve the request for the StaticLoggerBinder?

oberlies
  • 11,503
  • 4
  • 63
  • 110
Lars
  • 81
  • 1
  • 6

2 Answers2

0

My assumption is that the fragment is not part of the runtime configuration during the test execution.

I'm not a slf4j expert, but it sounds to be the root of the problem. You need to somehow specify with implementation behind slf4j you want.

BTW, you'll have the same problem in your product. How do you solve the problem there?


The recommendation for both problems is to create (or re-use) a feature which references the fragments you want to have. Once you have such a feature, you can

  1. include it in your product to make sure that logging works in the prduct installation, and

  2. include it in your test runtime to make logging work there. You can do this with the following configuration:

    <plugin>
      <groupId>org.eclipse.tycho</groupId>
      <artifactId>target-platform-configuration</artifactId>
      <version>${tycho-version}</version>
      <configuration>
        <dependency-resolution>
          <extraRequirements>
            <requirement>
              <type>eclipse-feature</type>
              <id>feature-referencing-the-logging-implementation-fragment</id>
              <versionRange>0.0.0</versionRange>
            </requirement>
          </extraRequirements>
        </dependency-resolution>
      </configuration>
    </plugin>
    
oberlies
  • 11,503
  • 4
  • 63
  • 110
0

Althought his is an old post, I ran into the same issue recently and hope my answer will help. The solution is to add the ch.qos.logback.slf4j fragment's jar to the JUnit test classpath. You will probably want to add the jar that resides in your eclipse/plugins folder to make sure the version matches the plugins on your eclipse installation.

Arcanefoam
  • 687
  • 7
  • 20