use of ch.qos.logback.core.Appender in project sling by apache.
the class LogbackManager method determineLoggerState.
// ~ ----------------------------------------------WebConsole Support
public LoggerStateContext determineLoggerState() {
final List<Logger> loggers = getLoggerContext().getLoggerList();
final LoggerStateContext ctx = new LoggerStateContext(loggers);
//2. Other means - Configured via Logback config or any other means
for (LogConfig lc : logConfigManager.getLogConfigs()) {
for (String category : lc.getCategories()) {
ctx.osgiConfiguredLoggers.put(category, lc);
}
}
for (Logger logger : loggers) {
boolean hasOnlySlingRollingAppenders = true;
Iterator<Appender<ILoggingEvent>> itr = logger.iteratorForAppenders();
while (itr.hasNext()) {
Appender<ILoggingEvent> a = itr.next();
if (a.getName() != null && !ctx.appenders.containsKey(a.getName())) {
ctx.appenders.put(a.getName(), a);
}
if (!(a instanceof SlingRollingFileAppender)) {
hasOnlySlingRollingAppenders = false;
}
}
if (logger.getLevel() == null) {
continue;
}
boolean configuredViaOSGiConfig = ctx.osgiConfiguredLoggers.containsKey(logger.getName());
if (!configuredViaOSGiConfig || (configuredViaOSGiConfig && !hasOnlySlingRollingAppenders)) {
ctx.nonOSgiConfiguredLoggers.add(logger);
}
}
return ctx;
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationConfigInstallerTest method testRunASE.
/**
* Tests the {@link ApplicationConfigInstaller#run()} method for the case
* where an ApplicationServiceException is thrown by appService.addApplication(..)
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRunASE() 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);
FeaturesService featuresService = mock(FeaturesService.class);
ApplicationService testAppService = mock(ApplicationServiceImpl.class);
doThrow(new ApplicationServiceException()).when(testAppService).startApplication(anyString());
URL fileURL = this.getClass().getResource("/" + GOOD_FILE);
ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(fileURL.getFile(), testAppService, featuresService, 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_ASE_EX);
}
}));
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationConfigInstallerTest method testRunInvalidURI.
/**
* Tests the {@link ApplicationConfigInstaller#run()} method to test if it handles
* an invalid URI cleanly
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRunInvalidURI() 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);
ApplicationServiceImpl testAppService = mock(ApplicationServiceImpl.class);
URL fileURL = this.getClass().getResource("/" + INVALID_FILE);
ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(fileURL.getFile(), testAppService, 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_INVALID_URI);
}
}));
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationUploadEndpointTest method testApplicationUploadEndpointCreateFileNotFound.
/**
* Tests the {@link ApplicationUploadEndpoint#create(MultipartBody, UriInfo)} method
* for the case where the file cannot be found (inside of createFileAttachement(..))
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testApplicationUploadEndpointCreateFileNotFound() 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);
ApplicationUploadEndpoint applicationUploadEndpoint = new ApplicationUploadEndpoint(testAppService);
testFile = new File(File.class.getResource(TEST_FILE_NAME).getPath());
testIS = null;
when(testDataHandler.getInputStream()).thenReturn(testIS);
when(testDisp.getParameter(FILENAME_CONTENT_DISPOSITION_PARAMETER_NAME)).thenReturn(TEST_FILE_NAME);
applicationUploadEndpoint.setDefaultFileLocation(TEST_FILE_LOCATION);
applicationUploadEndpoint.create(testMultipartBody, testUriInfo);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(FILE_NOT_FOUND);
}
}));
}
use of ch.qos.logback.core.Appender in project ddf by codice.
the class ApplicationUploadEndpointTest method testApplicationUploadEndpointCreateIOException.
/**
* Tests the {@link ApplicationUploadEndpoint#create(MultipartBody, UriInfo)} method
* for the case where the source file causes an IOException when it is read
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testApplicationUploadEndpointCreateIOException() 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);
ApplicationUploadEndpoint applicationUploadEndpoint = new ApplicationUploadEndpoint(testAppService);
doThrow(new IOException()).when(testDataHandler).getInputStream();
when(testDisp.getParameter(FILENAME_CONTENT_DISPOSITION_PARAMETER_NAME)).thenReturn(BAD_FILE_NAME);
applicationUploadEndpoint.setDefaultFileLocation(TEST_FILE_LOCATION);
applicationUploadEndpoint.create(testMultipartBody, testUriInfo);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains("ddf.home");
}
}));
}
Aggregations