| Logger-Layout? [message #928693] |
Sun, 30 September 2012 18:26  |
David Reichl Messages: 9 Registered: September 2012 |
Junior Member |
|
|
Hi,
I've just started using juno, and I'm trying to get used to die model (and of course with DI). For the beginning I injected a Logger (org.eclipse.e4.core.services.log.Logger) and it's working fine! Now I'm wondering how I could change the layout of the log-messages.? How can I do this? Is there a way like the properties-file in log4j?
Thanks!
|
|
|
|
|
|
| Re: Logger-Layout? [message #956075 is a reply to message #955149] |
Wed, 24 October 2012 04:14   |
Christoph Keimel Messages: 277 Registered: December 2010 Location: Germany |
Senior Member |
|
|
Hi David,
this is how I register an ILoggerProvider which uses slf4j as logging framework.
public class MyPlugin implements BundleActivator {
private ServiceRegistration<?> registration;
@Override
public void start(BundleContext bundleContext) throws Exception {
// Use SLF4J as LoggerProvider for e4
ILoggerProvider logService = new ILoggerProvider() {
@Override
public org.eclipse.e4.core.services.log.Logger getClassLogger(Class<?> clazz) {
return new Slf4jLoggerWrapper(LoggerFactory.getLogger(clazz));
}
};
registration = bundleContext.registerService(ILoggerProvider.class, logService, null);
}
@Override
public void stop(BundleContext bundleContext) throws Exception {
registration.unregister();
registration = null;
}
}
Greetings
Christoph
[Updated on: Thu, 25 October 2012 05:14] Report message to a moderator
|
|
|
|
| Re: Logger-Layout? [message #956896 is a reply to message #956293] |
Wed, 24 October 2012 18:08   |
David Reichl Messages: 9 Registered: September 2012 |
Junior Member |
|
|
thanks for your help! i know i'm a greenhorn but i'm trying to get use to eclipse...
just to be sure: the important thing is the "return new Slf4jLoggerWrapper(LoggerFactory.getLogger(clazz));".
so when i get this right i could create a LogFactory which returns a self-made Log4JLogger which extends org.eclipse.e4.core.services.log.Logger and where i have my "private org.apache.log4j.Logger log". in this Log4JLogger i implement for example the method "info" like this:
@Override
public void info(Throwable t, String message) {
if (this.isInfoEnabled()) {
this.log.info(buildLogMessage(message, null), t);
}
}
could that work?
[Updated on: Wed, 24 October 2012 18:39] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01950 seconds