Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Some questions about logging
Some questions about logging [message #662013] Mon, 28 March 2011 21:17 Go to next message
Karl Weber is currently offline Karl Weber
Messages: 63
Registered: September 2010
Member
I apologize for re-posting this in the right forum. I accidentally posted it in an inappropriate forum before.

In e4 there are two ways to log something:

  • The org.eclipse.e4.core.services.log.Logger
  • The org.osgi.service.log.LogService

As far as I understand it, these two things seem to be related in the sense that the first uses the second, i.e. the org.eclipse.e4.core.services.log.Logger uses the org.osgi.service.log.LogService. Is this correct?

I observed at least the following: If an RCP application uses some pure OSGi bundles that do not know anything but the OSGi specification and, thus, use the LogService, the messages end up in the same log file as the messages generated with the Logger. Is this part of the eclipse "API", i.e. will this always be the case, or is this a mere "accident"?

If this behaviour is intended, I do not understand why the OSGi specification is not strictly implemented: The LogService has two kinds of logging methods, e.g.
// first way
fLogService.log(LogService.LOG_ERROR, "This is my first log message");
//second way
fLogService.log(serviceReference, LogService.LOG_ERROR, "This is my first log message");

If I did not make a(nother) mistake, the LogEntry in the log file does not contain any service reference. I am no OSGi expert, but wouldn't this be a violation of the OSGi specification? Someone could get the log entries via org.osgi.service.log.LogReaderService.getLog(). This should return the log entries from the log file. The OSGi specification does not require this method to return all log entries. But I would expect that the log entries it does return are "complete".

Another point is that log entries created with the LogService correctly show the originating bundle while log entries created with the Logger all seem to show the bundle org.eclipse.e4.ui.workbench. This should be a bug or shouldn't it?

Or am I all wrong about this logging?
Re: Some questions about logging [message #662027 is a reply to message #662013] Mon, 28 March 2011 22:54 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5320
Registered: July 2009
Senior Member
Hi Karl,

I worked on the logging stuff some time before the 4.0 release to only
make it a bit more useable.

The logger you are seeing is the one the org.eclipse.e4.ui.workbench
injected into to context. Instead you should inject yourself the
ILoggerProvider which allows you to create a specific logger for this
class similar to the Logger.getLogger() works in case of log4j.

The API of the Logger we provide does NOT necessarily use the
OSGi-LogService (our default implementation though does) but should be
able to get replaced e.g. through log4j, ... .

Tom

Am 28.03.11 14:17, schrieb Karl Weber:
> I apologize for re-posting this in the right forum. I accidentally
> posted it in an inappropriate forum before.
>
> In e4 there are two ways to log something:
>
> The org.eclipse.e4.core.services.log.Logger
> The org.osgi.service.log.LogService
>
> As far as I understand it, these two things seem to be related in the
> sense that the first uses the second, i.e. the
> org.eclipse.e4.core.services.log.Logger uses the
> org.osgi.service.log.LogService. Is this correct?
>
> I observed at least the following: If an RCP application uses some pure
> OSGi bundles that do not know anything but the OSGi specification and,
> thus, use the LogService, the messages end up in the same log file as
> the messages generated with the Logger. Is this part of the eclipse
> "API", i.e. will this always be the case, or is this a mere "accident"?
>
> If this behaviour is intended, I do not understand why the OSGi
> specification is not strictly implemented: The LogService has two kinds
> of logging methods, e.g.
>
> // first way
> fLogService.log(LogService.LOG_ERROR, "This is my first log message");
> //second way
> fLogService.log(serviceReference, LogService.LOG_ERROR, "This is my
> first log message");
>
> If I did not make a(nother) mistake, the LogEntry in the log file does
> not contain any service reference. I am no OSGi expert, but wouldn't
> this be a violation of the OSGi specification? Someone could get the log
> entries via org.osgi.service.log.LogReaderService.getLog(). This should
> return the log entries from the log file. The OSGi specification does
> not require this method to return all log entries. But I would expect
> that the log entries it does return are "complete".
>
> Another point is that log entries created with the LogService correctly
> show the originating bundle while log entries created with the Logger
> all seem to show the bundle org.eclipse.e4.ui.workbench. This should be
> a bug or shouldn't it?
>
> Or am I all wrong about this logging?
Re: Some questions about logging [message #667657 is a reply to message #662013] Sat, 30 April 2011 18:13 Go to previous messageGo to next message
Karl Weber is currently offline Karl Weber
Messages: 63
Registered: September 2010
Member
Karl Weber wrote on Mon, 28 March 2011 23:17

In e4 there are two ways to log something:

  • The org.eclipse.e4.core.services.log.Logger
  • The org.osgi.service.log.LogService



I am not happy with Equinox's LogService, i.e. the stuff in org.eclipse.equinox.log.

One can disable this log service with the property -Dosgi.hook.configurators.exclude=org.eclipse.core.runtime.i nternal.adaptor.EclipseLogHook

Then one can provide one's own log service as a DS implementing the interface org.osgi.service.log.LogService.

This works pretty well in a pure OSGi Application, however it does not work with an e4 RCP application. I get the exception

osgi> org.eclipse.osgi Application error
org.eclipse.e4.core.di.InjectionException: Unable to process "WorkbenchLogger#setFrameworkLog()": no actual value was found for the argument "FrameworkLog".

So something seems still missing. Could you give me some help about what I have to implement in addition?
Re: Some questions about logging [message #667917 is a reply to message #667657] Mon, 02 May 2011 18:46 Go to previous messageGo to next message
Remy Suen is currently offline Remy Suen
Messages: 462
Registered: July 2009
Senior Member
It seems to me as though our Logger subclass expects a FrameworkLog instance (and not a LogService instance) to be available for it to function.
Re: Some questions about logging [message #670928 is a reply to message #667917] Mon, 16 May 2011 09:03 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 353
Registered: December 2010
Location: Germany
Senior Member
Hello,

I've been working on logging in e4 the last few days. The task was to combine different legacy loggings in a single configuration. This wonderfull blog helped a lot:
http://ekkescorner.wordpress.com/blog-series/osgi-apps/

Greetings,
Christoph
Re: Some questions about logging [message #671104 is a reply to message #670928] Mon, 16 May 2011 19:11 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5320
Registered: July 2009
Senior Member
Are there chance you could share your work with us?

Tom

Am 16.05.11 11:03, schrieb Christoph Keimel:
> Hello,
>
> I've been working on logging in e4 the last few days. The
> task was to combine different legacy loggings in a single
> configuration. This wonderfull blog helped a lot:
> http://ekkescorner.wordpress.com/blog-series/osgi-apps/
>
> Greetings,
> Christoph
Re: Some questions about logging [message #671673 is a reply to message #671104] Wed, 18 May 2011 16:23 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 353
Registered: December 2010
Location: Germany
Senior Member
Certainly Smile The exercise was to combine different kinds of logging under one framework. This way you can configure the logging in one single place. After following the blog mentioned above (thanks ekke!) I got a solution which satisfies this criteria.

A) SLF4J is used as Logging-API (with logback as implementation)
B) An ILoggerProvider is registered for e4 to use SL4J
C) java.util.Logging is rerouted to SLF4J with the SLF4JBridgeHandler
D) OSGI Logging is rerouted to SLF4J with de.emsw.osgi.log.over.slf4j
E) The configuration in done in the fragement de.emsw.gosa.logback.config

There is a lot to say about this, so please have a look at the projects attached. Start with de.emsw.gosa.product.logtest.LogTestPlugin (the Bundle Activator).

1) de.emsw.gosa.product.logtest
e4 Projekt with a part to enter Log Entries with different frameworks
2) de.emsw.gosa.logback.config
Fragement to configure the central logging framework (logback)
3) LogTarget
Target plug-ins to use

The plug-ins in LogTarget:
a) logback
The central logging framework; a native implementation of slf4j
see: Logback
The bundles were downloaded from springsource
b) slf4j
SLF4J libraries
see: SLF4J

I have not tested the jcl- and log4j-bridges because I do not need them. I have included the libraries in the sl4j folder, so you can include them if you wish.

One more notion to de.emsw.osgi.log.over.slf4j: I have renamed this plugin because I have stripped it's core to "just" rerouting the osgi log entries. Most of the code comes from Ekkehard Gentz who released it under the EPL. I'm new to public licenses, so I hope I repackaged it correctly. If not: Please give me a hint on how to do it properly.

Christoph
Re: Some questions about logging [message #674893 is a reply to message #671673] Sun, 29 May 2011 09:44 Go to previous messageGo to next message
Karl Weber is currently offline Karl Weber
Messages: 63
Registered: September 2010
Member
There are so many logging APIs that logging is a mess.

One can always try to unify logging using all kinds of bridges.

I do hope, however, that this will always remain optional. I definitely would not like to bloat any application with all kinds of logging-API bridges (and logging APIs) one does not actually need.

A minimal solution would support only the standard, i.e. java.util.logging and OSGi logging. Equinox already has the extended log service which is outside of any standard. This extension has one advantage, though: It allows to use java.util.logging and write a handler that bridges from java.util.logging to OSGi logging. This in turn allows to add logging to OSGi bundles, whose jar files can also be used outside of an OSGi framework. Any other bridge and any other logging API should be optional. -- Unfortunately, this bridge will not work on another OSGi framework...

By the way, is there a chance that the extended log service might enter the OSGi standard some day? If I remember right, this has been suggested some time ago?
Re: Some questions about logging [message #1005792 is a reply to message #662013] Mon, 28 January 2013 18:31 Go to previous message
Joseph Carroll is currently offline Joseph Carroll
Messages: 174
Registered: May 2012
Location: Milwaukee, WI
Senior Member

Anyone interested in this thread and the topic of logging within E4 will probably be interested in the enhancement I just submitted Class Logger Extended Object Supplier.

Now instead of have to directly use an ILoggerProvider you can just annotate your logger with @Inject @ClassLogger Logger and an instance of your logger will be injected. (Note: the instance will be separate from anything in the context)

For those hold outs to other logging facilities like Log4J, you are able to map o.e.e4.c.s.Logger to log4j.Logger as demonstrated in my sample project.

The one issue is that the context by default has an instance of Logger, thus the annotations of @Inject @ClassLogger Logger will not use the extended object supplier but the logger in the context. To resolve this issue just extend from Logger and inject your logger type (ex: @Inject @ClassLogger MyLogger).

This is all demonstrated in the sample project and is very easy and straight forward. If you like it, please +1 the enhancement in the attached bug.

JD
Previous Topic:Localization and extension-point schema definition errors
Next Topic:How do you inject the IEventBroker in an OSGi service ?
Goto Forum:
  


Current Time: Wed Sep 17 05:44:55 GMT 2014

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

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