Skip to main content
Jump to: navigation, search

SWTBot/MigrationToSLF4J


SWTBot
Website
Update Sites
Community
Mailing List
Forums/Newsgroups
IRC
Contribute
Open Bugzilla tickets
Open Gerrit reviews
Browse Source
Continuous Integration


Migration to SLF4J logging

SWTBot 4.0.0 has removed its use of org.apache.log4j and is instead using the org.slf4j.api facade for its logging. Migration to SLF4J gives the flexibility of using any of the logger, e.g. simple, log4j, logback, etc.


The users of SWTBot have to include one of the SLF4J Binders to get log messages from SWTBot tests.

The following messages will appear after running the test, when there is no SLF4J Binding-

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation

At this point, you have to start using SLF4J Binder.

This section illustrates one set of combinations that are tested with Eclipse 2022-06. There can be various such combinations.

Note- The versions of slf4j binding jars may vary depending upon the Eclipse version. It is important to pick the jars compatible to your Eclipse version from Orbit downloads.

Do not include multiple loggers at the same time in your application.

For simplicity, lib folder in the examples below is the folder in the plugin that contains the jars that are required in classpath. You may use any mechanism to get them in classpath.

Simple Logger-

1. Install SLF4J Simple Binding from Orbit. It will install org.slf4j.binding.simple jar.

2. MANIFEST.MF

 Import-Package: org.slf4j
 Bundle-ClassPath: .,
 lib/org.slf4j.api_1.7.30.v20200204-2150.jar,
 lib/org.slf4j.binding.simple_1.7.30.v20200204-2150.jar

3. Add simplelogger.properties at the root of the plugin.

4. Test code should define logger as:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SLF4JTest {
public static final Logger logger = LoggerFactory.getLogger(SLF4JTest.class); }


5. PDE SWTBot Run launch

Arguments tab can have level “-Dorg.slf4j.simpleLogger.defaultLogLevel=debug” if you want debug level messages.

Plugins tab- Include org.slf4j.binding.simple and org.slf4j.api along with other required plugins.


Log4j logger-

1. Install SLF4J log4j Binding and org.apache.log4j from Orbit. It will install org.slf4j.binding.log4j12 and org.apache.log4j jars. The versions of org.apache.log4j, log4j binder and slf4j should be compatible.

org.slf4j.impl.log4j12 is also one option that works with older versions of Eclipse.

Do not use multiple implementations and bridges of log4j; otherwise it will cause StackOverflow.

2. MANIFEST.MF

 Import-Package: org.slf4j
 Bundle-ClassPath: .,
 lib/org.apache.log4j_1.2.19.v20220208-1728.jar,
 lib/org.slf4j.api_1.7.30.v20200204-2150.jar,
 lib/org.slf4j.binding.log4j12_1.7.30.v20201108-2042.jar

3. Add log4j.properties at the root of the plugin. If you want to get debug messages in log, you need to set ‘threshold’ property of the Appender.

4. Define logger in your test code as above.

5. PDE SWTBot Run launch

Plugins tab- Include org.slf4j.binding.log4j12 , org.apache.log4j and org.slf4j.api along with other required plugins.


Logback logger-

1. Install Logback SLF4J Binding, Logback Classic Module and Core Module from Orbit. It will install ch.qos.logback.classic, ch.qos.logback.Core and ch.qos.logback.slf4j

2. MANIFEST.MF

 Require-Bundle: org.eclipse.swtbot.go,
 ch.qos.logback.classic,
 ch.qos.logback.core
 Import-Package: org.slf4j
 Bundle-ClassPath: .,
 lib/ch.qos.logback.slf4j_1.2.3.v20200428-2012.jar


3. Define logger in your test code as above.

4. PDE SWTBot Run launch

Plugins tab- Include ch.qos.logback.classic, ch.qos.logback.core, ch.qos.logback.slf4j and org.slf4j.api along with other required plugins.

Back to the top