use of ch.qos.logback.core.Appender in project ddf by codice.
the class AllApplicationsCompleterTest method testAllApplicationsCompleterNullAppService.
/**
* Tests the {@link AllApplicationsCompleter#complete(String, int, List)} method
* for the case where the ApplicationService given to it is null
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testAllApplicationsCompleterNullAppService() {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
root.setLevel(Level.ALL);
ApplicationService testAppService = null;
AllApplicationsCompleter allApplicationsCompleter = new AllApplicationsCompleter();
allApplicationsCompleter.setApplicationService(testAppService);
allApplicationsCompleter.complete(null, commandLine, new ArrayList<>());
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(NO_APP_SERV);
}
}));
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationServiceBeanTest method testAddApplicationsASE.
/**
* Tests the {@link ApplicationServiceBean#addApplications(List)} method
* for the case where an ApplicationServiceException is thrown
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testAddApplicationsASE() throws Exception {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
root.setLevel(Level.ALL);
ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt, mBeanServer);
List<Map<String, Object>> testURLList = new ArrayList<>();
Map<String, Object> testURLMap1 = mock(HashMap.class);
when(testURLMap1.get("value")).thenReturn(TEST_URL);
Map<String, Object> testURLMap2 = mock(HashMap.class);
when(testURLMap2.get("value")).thenReturn(TEST_URL);
testURLList.add(testURLMap1);
testURLList.add(testURLMap2);
doThrow(new ApplicationServiceException()).when(testAppService).addApplication(any(URI.class));
serviceBean.addApplications(testURLList);
verify(mockAppender, times(2)).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(ADD_APP_ASE);
}
}));
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationServiceBeanTest method testGetServicesASE.
/**
* Tests the {@link ApplicationServiceBean#getServices(String)} method
* for the case where an ApplicationServiceException is thrown
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testGetServicesASE() throws Exception {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
root.setLevel(Level.ALL);
ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt, mBeanServer) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
Bundle testBundle = mock(Bundle.class);
Bundle[] bundles = { testBundle };
when(bundleContext.getBundles()).thenReturn(bundles);
List<Map<String, Object>> services = new ArrayList<>();
Map<String, Object> testService1 = new HashMap<>();
services.add(testService1);
doThrow(new ApplicationServiceException()).when(testApp).getBundles();
when(testAppService.getApplication(TEST_APP_NAME)).thenReturn(testApp);
when(testConfigAdminExt.listServices(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(services);
serviceBean.getServices(TEST_APP_NAME);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(GET_SERV_ASE);
}
}));
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationConfigInstallerTest method testRunConfigFileNotExist.
/**
* Tests the {@link ApplicationConfigInstaller#run()} method for the case
* where the configFile doesn't exist
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRunConfigFileNotExist() throws Exception {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
root.setLevel(Level.ALL);
ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(BAD_FILE, null, null, START_FEATURE, STOP_FEATURE);
configInstaller.run();
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(RUN_NO_CONFIG);
}
}));
}
use of ch.qos.logback.core.Appender in project uplace.es by Uplace.
the class LoggingConfiguration method setMetricsMarkerLogbackFilter.
// Configure a log filter to remove "metrics" logs from all appenders except the "LOGSTASH" appender
private void setMetricsMarkerLogbackFilter(LoggerContext context) {
log.info("Filtering metrics logs from all appenders except the {} appender", LOGSTASH_APPENDER_NAME);
OnMarkerEvaluator onMarkerMetricsEvaluator = new OnMarkerEvaluator();
onMarkerMetricsEvaluator.setContext(context);
onMarkerMetricsEvaluator.addMarker("metrics");
onMarkerMetricsEvaluator.start();
EvaluatorFilter<ILoggingEvent> metricsFilter = new EvaluatorFilter<>();
metricsFilter.setContext(context);
metricsFilter.setEvaluator(onMarkerMetricsEvaluator);
metricsFilter.setOnMatch(FilterReply.DENY);
metricsFilter.start();
for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
for (Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders(); it.hasNext(); ) {
Appender<ILoggingEvent> appender = it.next();
if (!appender.getName().equals(ASYNC_LOGSTASH_APPENDER_NAME)) {
log.debug("Filter metrics logs from the {} appender", appender.getName());
appender.setContext(context);
appender.addFilter(metricsFilter);
appender.start();
}
}
}
}
Aggregations