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.
- Download log4j
- Extract log4j.jar to a directory in your plugin bundle layout. (e.g. /lib)
- Add an entry in MANIFEST.MF, Bundle-ClassPath: .. ,lib/log4j.jar ,..
- Create a log4j properties file somewhere in your plugin bundle layout. (/log4j/log4j.properties)
- public static final Logger log = Logger.getLogger(“com.mycompany”);
- PropertyConfigurator.configure(findFile(“/log4j/log4j.properties”));
- 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”