[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] Safe logging from a WeavingHook?

> From: Stephan Herrmann
> Hi Tom,
> Thanks for your comprehensive answer.
> Yes, we can easily agree that SynchronousLogListener is dangerous :)
> More questions inline ...
> Sounds promising, but ...
> >  But be aware that nobody is going to see your logs until there is
> a org.osgi.service.log.LogService registered to
> > listen to your logs.
> ... is that s.t. I have to register? How?
> Can I hook this up so that all entries do (eventually) appear in the
> Errors view and perhaps the persistent log file?

I did not mean LogService there.  I meant org.osgi.service.log.LogListener.  You would have to register a LogListener with the LogReaderService using the method:


This would be a bit tricky, this listener would get LogEntry events asynchronously.  It could then turn around and call the Equinox Logger for the with the name "org.eclipse.equinox.logger" to force it into the persistent log (which shows up in the log view.

> > The one exception to this rule is when the LogEntry is of type
> ERROR, in that case the log will be sent to the
> > persistent eclipse log file BUT it WILL NOT be sent to the
> listeners registered with the org.eclipse.core.runtime.ILog.
> >
> > I'm unsure what you are trying to log, but if it is simply ERRORs
> then I would use the standard org.osgi.service.log.LogService
> I'm using it for all kinds of things. The particular dangerous case
> was logging
> profiling data at level INFO.

Then I suggest you use your own logger name and use it to call org.eclipse.equinox.log.ExtendedLogService.getLogger(String) and use the Logger to log all your messages.  Then register a LogListener with the method org.eclipse.equinox.log.ExtendedLogReaderService.addLogListener(LogListener, LogFilter) with a filter that returns true only when the loggerName equals your logger name.  This LogListener would then turn around and call the Logger with the name "org.eclipse.equinox.logger" to post the messages to the persistent log.  Note this will also send the log to the pesky synchronous ILog listeners, but now we are on a separate thread.