Debugging applications for the platform
The SmartProducts platform is organized as OSGi bundles and uses felix as its OSGi framework. Thus, we decided to rely on an OSGi debugging fascade called SLF4J (Simple Logging Facade for Java). SLF4J wraps in our case the log4J logging API and allows developers to use e.g. Apache Chainsaw as a debugging client.
To use the debugging framework, you basically need to perform the following steps.
Step 1
Include the SLF4J API to the build path of your project. The current version of the used API can be found under /3rdparty-lib/slf4j-api-1.6.0.jar.
Step 2
Add the imports:
1 2
|
import org.slf4j.Logger; import org.slf4j.LoggerFactory;
|
Create a logger:
1
|
private Logger _logger = LoggerFactory.getLogger(BasicInteractionManager.class);
|
Use the logger:
1
|
_logger.info("InteractionManager used config file: " + context.getProperty("eu.smartproducts.interaction.InteractionManager").trim());
|
Step 3
Setup the log4j config file (log4j.properties), which should be placed in the conf folder in your distrribution. A default config file can be found in the SVN under platform/trunk/default-product-env/conf.
The default configuration contains a console appender and a chainsaw client appender, whereby the last one is set active:
#define the console appender log4j.appender.consoleAppender = org.apache.log4j.ConsoleAppender log4j.appender.consoleAppender.layout = org.apache.log4j.PatternLayout log4j.appender.consoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n #define chainsaw appender log4j.appender.CHAINSAW_CLIENT=org.apache.log4j.net.SocketAppender log4j.appender.CHAINSAW_CLIENT.RemoteHost=localhost log4j.appender.CHAINSAW_CLIENT.Port=4445 log4j.appender.CHAINSAW_CLIENT.locationInfo=true # Using chainsaw as debug GUI log4j.rootLogger=DEBUG, CHAINSAW_CLIENT
Step 4
Create the distribution of your application and make sure, the right log4j.properties is placed in the /conf folder.
Step 5
Run Chainsaw and select a simple socket reciever on port 4445:

Step 6
Start the platform and inspect your logger:
|