use of org.osgi.service.log.LogEntry in project sling by apache.
the class LogSupport method serviceChanged.
// ---------- ServiceListener ----------------------------------------------
/**
* Listens for Service events and logs the respective events according to
* the Log Service specification.
*/
public void serviceChanged(ServiceEvent event) {
int level = LogService.LOG_INFO;
String message;
switch(event.getType()) {
case ServiceEvent.REGISTERED:
message = "ServiceEvent REGISTERED";
break;
case ServiceEvent.MODIFIED:
message = "ServiceEvent MODIFIED";
level = LogService.LOG_DEBUG;
break;
case ServiceEvent.UNREGISTERING:
message = "ServiceEvent UNREGISTERING";
break;
default:
message = "ServiceEvent " + event.getType();
}
LogEntry entry = new LogEntryImpl(event.getServiceReference().getBundle(), event.getServiceReference(), level, message, null);
fireLogEvent(entry);
}
use of org.osgi.service.log.LogEntry in project sling by apache.
the class LogSupportTest method testWarningLogger.
@Test
public void testWarningLogger() throws Exception {
Exception e = new Exception();
LogEntry le = new LogEntryImpl(bundle, null, LogService.LOG_WARNING, "my-warning-message", e);
logSupport.fireLogEvent(le);
Mockito.verify(testLogger).warn("my-warning-message (java.lang.Exception)", e);
}
use of org.osgi.service.log.LogEntry in project sling by apache.
the class LogSupportTest method testEarlyExit.
@Test
public void testEarlyExit() throws Exception {
ServiceReference sr = Mockito.mock(ServiceReference.class);
LogEntry le = new LogEntryImpl(bundle, sr, LogService.LOG_DEBUG, "test", null);
logSupport.fireLogEvent(le);
// The log message is on DEBUG level while the logger is set to INFO level
// we don't want the actual log.info() call to be made, neither do we want
// any preparatory work on the log message being made (which involves
// inspecting the service reference).
Mockito.verify(testLogger).isTraceEnabled();
Mockito.verify(testLogger).isDebugEnabled();
Mockito.verify(testLogger).isInfoEnabled();
Mockito.verifyNoMoreInteractions(testLogger);
Mockito.verifyZeroInteractions(sr);
}
use of org.osgi.service.log.LogEntry in project sling by apache.
the class LogSupportTest method testErrorLogger.
@Test
public void testErrorLogger() throws Exception {
Exception e = new Exception();
LogEntry le = new LogEntryImpl(bundle, null, LogService.LOG_ERROR, "my-error-msg", e);
logSupport.fireLogEvent(le);
Mockito.verify(testLogger).error("my-error-msg (java.lang.Exception)", e);
}
use of org.osgi.service.log.LogEntry in project felix by apache.
the class Basic method log.
@Descriptor("display some matching log entries")
public void log(@Descriptor("maximum number of entries") int maxEntries, @Descriptor("minimum log level [ debug | info | warn | error ]") String logLevel) {
// Keep track of service references.
List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
// Get start level service.
LogReaderService lrs = Util.getService(m_bc, LogReaderService.class, refs);
if (lrs == null) {
System.out.println("Log reader service is unavailable.");
} else {
@SuppressWarnings("unchecked") Enumeration<LogEntry> entries = lrs.getLog();
int minLevel = logLevelAsInt(logLevel);
int index = 0;
while (entries.hasMoreElements() && (maxEntries < 0 || index < maxEntries)) {
LogEntry entry = (LogEntry) entries.nextElement();
if (entry.getLevel() <= minLevel) {
display(entry);
index++;
}
}
Util.ungetServices(m_bc, refs);
}
}
Aggregations