Search in sources :

Example 21 with Appender

use of ch.qos.logback.core.Appender in project gocd by gocd.

the class FileLocationProvider method asJson.

@Override
public Map<String, Object> asJson() {
    LinkedHashMap<String, Object> json = new LinkedHashMap<>();
    json.put("loc.config.dir", systemEnvironment.configDir().getAbsolutePath());
    List<Logger> loggers = LOGGER_CONTEXT.getLoggerList();
    Appender[] appenders = getAppenders(loggers);
    for (int i = 0; i < appenders.length; i++) {
        Appender appender = appenders[i];
        if (!isFileAppender(appender)) {
            continue;
        }
        FileAppender fileAppender = (FileAppender) appender;
        File logFile = new File(fileAppender.rawFileProperty());
        json.put("loc.log.root." + i, new File(logFile.getAbsolutePath()).getParent());
        json.put("loc.log.basename." + i, logFile.getName());
    }
    return json;
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) FileAppender(ch.qos.logback.core.FileAppender) Logger(ch.qos.logback.classic.Logger) File(java.io.File)

Example 22 with Appender

use of ch.qos.logback.core.Appender in project netty by netty.

the class SingleThreadEventLoopTest method testRegistrationAfterShutdown2.

@Test(timeout = 10000)
@SuppressWarnings("deprecation")
public void testRegistrationAfterShutdown2() throws Exception {
    loopA.shutdown();
    final CountDownLatch latch = new CountDownLatch(1);
    Channel ch = new LocalChannel();
    ChannelPromise promise = ch.newPromise();
    promise.addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            latch.countDown();
        }
    });
    // Disable logging temporarily.
    Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    List<Appender<ILoggingEvent>> appenders = new ArrayList<Appender<ILoggingEvent>>();
    for (Iterator<Appender<ILoggingEvent>> i = root.iteratorForAppenders(); i.hasNext(); ) {
        Appender<ILoggingEvent> a = i.next();
        appenders.add(a);
        root.detachAppender(a);
    }
    try {
        ChannelFuture f = loopA.register(promise);
        f.awaitUninterruptibly();
        assertFalse(f.isSuccess());
        assertThat(f.cause(), is(instanceOf(RejectedExecutionException.class)));
        // Ensure the listener was notified.
        assertFalse(latch.await(1, TimeUnit.SECONDS));
        assertFalse(ch.isOpen());
    } finally {
        for (Appender<ILoggingEvent> a : appenders) {
            root.addAppender(a);
        }
    }
}
Also used : Appender(ch.qos.logback.core.Appender) LocalChannel(io.netty.channel.local.LocalChannel) LocalChannel(io.netty.channel.local.LocalChannel) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 23 with Appender

use of ch.qos.logback.core.Appender in project netty by netty.

the class SingleThreadEventLoopTest method testRegistrationAfterShutdown.

@Test(timeout = 10000)
@SuppressWarnings("deprecation")
public void testRegistrationAfterShutdown() throws Exception {
    loopA.shutdown();
    // Disable logging temporarily.
    Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    List<Appender<ILoggingEvent>> appenders = new ArrayList<Appender<ILoggingEvent>>();
    for (Iterator<Appender<ILoggingEvent>> i = root.iteratorForAppenders(); i.hasNext(); ) {
        Appender<ILoggingEvent> a = i.next();
        appenders.add(a);
        root.detachAppender(a);
    }
    try {
        ChannelFuture f = loopA.register(new LocalChannel());
        f.awaitUninterruptibly();
        assertFalse(f.isSuccess());
        assertThat(f.cause(), is(instanceOf(RejectedExecutionException.class)));
        assertFalse(f.channel().isOpen());
    } finally {
        for (Appender<ILoggingEvent> a : appenders) {
            root.addAppender(a);
        }
    }
}
Also used : Appender(ch.qos.logback.core.Appender) LocalChannel(io.netty.channel.local.LocalChannel) ArrayList(java.util.ArrayList) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Example 24 with Appender

use of ch.qos.logback.core.Appender in project sonarqube by SonarSource.

the class CeProcessLoggingTest method startup_logger_prints_to_only_to_system_out.

@Test
public void startup_logger_prints_to_only_to_system_out() {
    LoggerContext ctx = underTest.configure(props);
    Logger startup = ctx.getLogger("startup");
    assertThat(startup.isAdditive()).isFalse();
    Appender appender = startup.getAppender("CONSOLE");
    assertThat(appender).isInstanceOf(ConsoleAppender.class);
    ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) appender;
    assertThat(consoleAppender.getTarget()).isEqualTo("System.out");
    assertThat(consoleAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
    PatternLayoutEncoder patternEncoder = (PatternLayoutEncoder) consoleAppender.getEncoder();
    assertThat(patternEncoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level app[][%logger{20}] %msg%n");
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) ConsoleAppender(ch.qos.logback.core.ConsoleAppender) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 25 with Appender

use of ch.qos.logback.core.Appender in project sonarqube by SonarSource.

the class WebServerProcessLoggingTest method do_not_log_to_console.

@Test
public void do_not_log_to_console() {
    LoggerContext ctx = underTest.configure(props);
    Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
    Appender appender = root.getAppender("CONSOLE");
    assertThat(appender).isNull();
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) 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