02
Jan
08

Eclipse PDE & log4j

In continuation of my quick and dirty tips for eclipse , if you’re developing an eclipse plugin, and want to use log4j in it, this is what you should do.

  1. Download log4j
  2. Extract log4j.jar to a directory in your plugin bundle layout. (e.g. /lib)
  3. Add an entry in MANIFEST.MF, Bundle-ClassPath: .. ,lib/log4j.jar ,..
  4. Create a log4j properties file somewhere in your plugin bundle layout. (/log4j/log4j.properties)
  5. public static final Logger log = Logger.getLogger(“com.mycompany”);
  6. PropertyConfigurator.configure(findFile(“/log4j/log4j.properties”));
  7. Anywhere in your code: log.info(“hello world”);

Heres how findFile works:

public static String findFile(String file)
{
String result=”";
try
{
result= FileLocator.toFileURL(FileLocator.find(getDefault().getBundle(), new Path(file), null)).getPath().toString();
}
catch(IOException ex)
{
ex.printStackTrace();
}
return result;
}


0 Responses to “Eclipse PDE & log4j”



  1. No Comments Yet

Leave a Reply