|
|
|
|
Re: Logger-Layout? [message #956075 is a reply to message #955149] |
Wed, 24 October 2012 08:14 |
Christoph Keimel Messages: 482 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 09:14] Report message to a moderator
|
|
|
|
Re: Logger-Layout? [message #956896 is a reply to message #956293] |
Wed, 24 October 2012 22: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 22:39] Report message to a moderator
|
|
|
|
|
Re: Logger-Layout? [message #960629 is a reply to message #959601] |
Sat, 27 October 2012 17:08 |
Eclipse User |
|
|
|
A few comments:
- Injection will fail if there's no MContribution available. You can use @Optional to avoid that so that the injector will inject "null" if not found.
- But remember that the injector will normally traverse up the context hierarchy to resolve values. So your MContribution may in fact come from the injection-requestor's ancestor instead. You may choose to be injected with the IEclipseContext instead: you can then request local resolution of different values within that context.
- I don't remember the scoping of @Creatable: IIRC the Creatable instance is remembered for that context and its descendants. So it you request a Logger from the MApplication, then that single logger instance will be used for all windows & parts. If you instead provide a context function (either declaratively through an OSGi Declarative Services, as an OSGi Service, or by registering a ContextFunction object with a context), you can compute and return a result on each injection: the value returned isn't placed into the context unless your context function explicitly places it into the context.
|
|
|
Re: Logger-Layout? [message #1691095 is a reply to message #959601] |
Thu, 02 April 2015 10:00 |
|
@David,
thanks for sharing all this, and thanks to all helpers.
Would you please share your Log4j org.eclipse.e4.core.services.log.Logger here? Might be useful to more than one.
@All
Btw: what if I don't want to use external logging libraries (Log4j, Slf4j, etc.) ? What is the default logger provider and how can I fetch it?
Thank you very much,
-Piero
[Updated on: Thu, 02 April 2015 10:01] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04973 seconds