Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » read log programmatically
read log programmatically [message #1067009] Fri, 05 July 2013 12:14 Go to next message
Jan Weidauer is currently offline Jan Weidauer
Messages: 49
Registered: July 2009
Member
Hi there,

I am looking for a way to read the log in my RCP programmatically.
I tried this
ServiceReference<LogReaderService> serviceReference =
context.getServiceReference(LogReaderService.class);
LogReaderService service = context.getService(serviceReference);
Enumeration log2 = service.getLog();
Object object;
while(log2.hasMoreElements()) {
object = log2.nextElement();
System.out.println(object);
}
but the Enumeration contains just an empty collection. How do I read the
log in e4 without compatibility layer?

Regards,

Jan
Re: read log programmatically [message #1067023 is a reply to message #1067009] Fri, 05 July 2013 13:17 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 371
Registered: December 2010
Location: Germany
Senior Member
Hi Jan

we register our own LoggerProvider, so that the Platform uses the same Logging-Framework than our application. In our case this is SLF4J.

@Override
public void start(BundleContext bundleContext) throws Exception {
	// Use SLF4J as LoggerProvider for e4
	ILoggerProvider service = new ILoggerProvider() {
		@Override
		public org.eclipse.e4.core.services.log.Logger getClassLogger(Class<?> clazz) {
			return new Slf4jLoggerWrapper(LoggerFactory.getLogger(clazz));
		}
	};
	bundleContext.registerService(ILoggerProvider.class.getName(), service, null);
}


Hope this helps!
Christoph
Re: read log programmatically [message #1067137 is a reply to message #1067023] Sat, 06 July 2013 08:44 Go to previous message
Frank Schaare is currently offline Frank Schaare
Messages: 8
Registered: July 2009
Junior Member
Hi,
Christoph Keimel wrote on Fri, 05 July 2013 09:17

we register our own LoggerProvider, so that the Platform uses the same Logging-Framework than our application. In our case this is SLF4J.

nice Approach.
You may also ask yourself: Do i need logging ?

EventBroker can be used for messaging and gives you high flexibility passing your own Objects to the bus:
broker.send(Topics.LOGGING, "message");

This solves the problem with yet missing ConsoleView too; you can now easily create a Console Part holding a message Table and consume logging information like:
@Inject
@Optional
public void handleEvent(@UIEventTopic(Topics.LOGGING) String msg){}

You can pass complex Error Objects holding IStatus & Exceptions to the broker.
You may easily implement a ConsoleHandler which writes all your stuff to the console.
So again: who needs logging in an e4 Application ?



Previous Topic:E4 demos exist?
Next Topic:Error on Startup - Could not run processor
Goto Forum:
  


Current Time: Fri Oct 31 08:34:16 GMT 2014

Powered by FUDForum. Page generated in 0.02092 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software