Search in sources :

Example 31 with Appender

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;
}
Also used : Appender(ch.qos.logback.core.Appender) SlingRollingFileAppender(org.apache.sling.commons.log.logback.internal.util.SlingRollingFileAppender) SlingRollingFileAppender(org.apache.sling.commons.log.logback.internal.util.SlingRollingFileAppender) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 32 with Appender

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);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) URL(java.net.URL) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) ArgumentMatcher(org.mockito.ArgumentMatcher) FeaturesService(org.apache.karaf.features.FeaturesService) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 33 with Appender

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);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) ArgumentMatcher(org.mockito.ArgumentMatcher) Logger(org.slf4j.Logger) URL(java.net.URL) Test(org.junit.Test)

Example 34 with Appender

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);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) ArgumentMatcher(org.mockito.ArgumentMatcher) Logger(org.slf4j.Logger) File(java.io.File) Test(org.junit.Test)

Example 35 with Appender

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");
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) ArgumentMatcher(org.mockito.ArgumentMatcher) IOException(java.io.IOException) Logger(org.slf4j.Logger) Test(org.junit.Test)

Aggregations

Appender (ch.qos.logback.core.Appender)50 Test (org.junit.Test)36 Logger (org.slf4j.Logger)26 ArgumentMatcher (org.mockito.ArgumentMatcher)23 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)15 Logger (ch.qos.logback.classic.Logger)14 FileAppender (ch.qos.logback.core.FileAppender)14 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)13 LoggerContext (ch.qos.logback.classic.LoggerContext)12 FeaturesService (org.apache.karaf.features.FeaturesService)10 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)9 HashSet (java.util.HashSet)9 Repository (org.apache.karaf.features.Repository)9 File (java.io.File)8 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)8 ArrayList (java.util.ArrayList)7 Application (org.codice.ddf.admin.application.service.Application)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AsyncAppender (ch.qos.logback.classic.AsyncAppender)2