use of org.osgi.service.log.LogEntry in project felix by apache.
the class LogListenerThread method run.
/**
* The main method of the thread: waits for new messages to be receieved
* and then delivers them to any registered log listeners.
*/
public void run() {
while (!isInterrupted()) {
List entriesToDeliver = new ArrayList();
synchronized (m_entriesToDeliver) {
if (m_entriesToDeliver.isEmpty()) {
try {
m_entriesToDeliver.wait();
} catch (InterruptedException e) {
// the interrupt-flag is cleared; so, let's play nice and
// interrupt this thread again to stop it...
interrupt();
}
} else {
// Copy all current entries and deliver them in a single go...
entriesToDeliver.addAll(m_entriesToDeliver);
m_entriesToDeliver.clear();
}
}
if (!entriesToDeliver.isEmpty()) {
// Take a snapshot of all current listeners and deliver all
// pending messages to them...
List listeners = new ArrayList();
synchronized (m_listeners) {
listeners.addAll(m_listeners);
}
Iterator entriesIt = entriesToDeliver.iterator();
while (entriesIt.hasNext()) {
LogEntry entry = (LogEntry) entriesIt.next();
Iterator listenerIt = listeners.iterator();
while (listenerIt.hasNext()) {
LogListener listener = (LogListener) listenerIt.next();
try {
listener.logged(entry);
} catch (Throwable t) {
// catch and discard any exceptions thrown by the listener
}
}
}
}
}
}
use of org.osgi.service.log.LogEntry in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testOverrideEquinoxConfigAreaProp.
public void testOverrideEquinoxConfigAreaProp() {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map configuration = new HashMap();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
configuration.put(EquinoxLocations.PROP_CONFIG_AREA, config.getAbsolutePath() + "-override");
configuration.put(EquinoxConfiguration.PROP_LOG_HISTORY_MAX, "10");
Equinox equinox = null;
try {
equinox = new Equinox(configuration);
equinox.init();
BundleContext bc = equinox.getBundleContext();
LogReaderService logReader = bc.getService(bc.getServiceReference(LogReaderService.class));
Enumeration<LogEntry> logs = logReader.getLog();
assertTrue("No logs found.", logs.hasMoreElements());
LogEntry entry = logs.nextElement();
assertEquals("Wrong log level.", LogLevel.WARN, entry.getLogLevel());
assertTrue("Wrong message found: " + entry.getMessage(), entry.getMessage().contains(EquinoxLocations.PROP_CONFIG_AREA));
} catch (BundleException e) {
fail("Failed init", e);
} finally {
try {
if (equinox != null) {
equinox.stop();
equinox.waitForStop(1000);
}
} catch (BundleException e) {
fail("Failed to stop framework.", e);
} catch (InterruptedException e) {
fail("Failed to stop framework.", e);
}
}
}
use of org.osgi.service.log.LogEntry in project vespa by vespa-engine.
the class ConsoleLogFormatterTestCase method requireThatMessageIsOptional.
@Test
public void requireThatMessageIsOptional() {
LogEntry entry = new MyEntry(0, 0, null);
assertEquals("0.000\t-\t-\t-\t-\tunknown\t", SIMPLE_FORMATTER.formatEntry(entry));
}
use of org.osgi.service.log.LogEntry in project vespa by vespa-engine.
the class ConsoleLogFormatterTestCase method requireThatBundleAndLoggerNameIsCombined.
@Test
public void requireThatBundleAndLoggerNameIsCombined() {
LogEntry entry = new MyEntry(0, 0, null).setBundleSymbolicName("bundleName").putProperty("LOGGER_NAME", "loggerName");
assertEquals("0.000\t-\t-\t-\tbundleName/loggerName\tunknown\t", SIMPLE_FORMATTER.formatEntry(entry));
}
use of org.osgi.service.log.LogEntry in project vespa by vespa-engine.
the class ConsoleLogFormatterTestCase method requireThatBundleNameIsIncluded.
@Test
public void requireThatBundleNameIsIncluded() {
LogEntry entry = new MyEntry(0, 0, null).setBundleSymbolicName("bundleName");
assertEquals("0.000\t-\t-\t-\tbundleName\tunknown\t", SIMPLE_FORMATTER.formatEntry(entry));
}
Aggregations