I have created an eclipse RCP Plugin for custom Logging API using log4j. my logging API prints log on console only. I want to print them in Eclipse Error Log View. Please suggest how to do this in eclipse RCP plugin.
I tried ILogListner and StatusManager but couldn't succeed. Please give some suggestions or sample code regarding this use case.
here I write custom appender and add this appender to my Logger.
public class VirtualConsole extends ConsoleAppender{
@Override
public void append(LoggingEvent event) {
int level = IStatus.INFO;
if (event.getLevel().equals(Level.ERROR))
level = IStatus.ERROR;
IStatus status = new Status(level, event.categoryName,event.getMessage().toString());
StatusManager.getManager().handle(status, StatusManager.LOG|StatusManager.SHOW);
//and the normal logging
super.append(event);
}
}
LoggerService.java
private static Logger LOGGER = Logger.getLogger(LoggerService.class.getName());
VirtualConsole v = new VirtualConsole();
LOGGER.addAppender(v);
My log4j.properties file
#Define root logger options
log4j.rootLogger=debug, console
#Define console appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
logrj.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-5p %c{1} - %m%n
LoggerService is an OSGI Service which is a custom logger service based on log4j.
I have a client code which consumes this LoggerService and uses log method.
whenever client invoke any LoggerService method (i.e loggerService.info("msg")
) this message is logged into the console but I want to log in eclipse Error view.
I already referred eclipse plugin development: error logging in log4j to error view
Note:- both client and service is an OSGI bundle.
Update:- i have on Logger Service OSGI bundle which return lo4j instance to another Client OSGI bundle and then client use this service for logging.