Search in sources :

Example 56 with Appender

use of ch.qos.logback.core.Appender in project qpid-broker-j by apache.

the class JDBCVirtualHostLoggerImplTest method createAppenderOnOpen.

@Test
public void createAppenderOnOpen() {
    _logger.open();
    final Appender appender = ROOT_LOGGER.getAppender(getTestName());
    assertTrue(appender instanceof DBAppender);
}
Also used : DBAppender(ch.qos.logback.classic.db.DBAppender) Appender(ch.qos.logback.core.Appender) DBAppender(ch.qos.logback.classic.db.DBAppender) Test(org.junit.Test)

Example 57 with Appender

use of ch.qos.logback.core.Appender in project qpid-broker-j by apache.

the class JDBCVirtualHostLoggerImplTest method detachAppenderInstanceOnDelete.

@Test
public void detachAppenderInstanceOnDelete() {
    _logger.create();
    _logger.delete();
    final Appender appender = ROOT_LOGGER.getAppender(getTestName());
    assertNull(appender);
}
Also used : DBAppender(ch.qos.logback.classic.db.DBAppender) Appender(ch.qos.logback.core.Appender) Test(org.junit.Test)

Example 58 with Appender

use of ch.qos.logback.core.Appender in project qpid-broker-j by apache.

the class BrokerLoggerTest method setUp.

@Before
public void setUp() throws Exception {
    _taskExecutor = new TaskExecutorImpl();
    _taskExecutor.start();
    _loggerAppender = new ListAppender<>();
    _loggerAppender.setName(APPENDER_NAME);
    Model model = BrokerModel.getInstance();
    _broker = mock(Broker.class);
    when(_broker.getCategoryClass()).thenReturn(Broker.class);
    when(_broker.getTypeClass()).thenReturn(Broker.class);
    when(_broker.getModel()).thenReturn(model);
    when(_broker.getChildExecutor()).thenReturn(_taskExecutor);
    doReturn(Broker.class).when(_broker).getCategoryClass();
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("name", APPENDER_NAME);
    _brokerLogger = new AbstractBrokerLogger(attributes, _broker) {

        @Override
        public Appender<ILoggingEvent> createAppenderInstance(Context context) {
            return _loggerAppender;
        }
    };
    _brokerLogger.open();
}
Also used : Context(ch.qos.logback.core.Context) Appender(ch.qos.logback.core.Appender) ListAppender(ch.qos.logback.core.read.ListAppender) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) Broker(org.apache.qpid.server.model.Broker) HashMap(java.util.HashMap) BrokerModel(org.apache.qpid.server.model.BrokerModel) Model(org.apache.qpid.server.model.Model) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Before(org.junit.Before)

Example 59 with Appender

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

the class HttpProtocolsTests method testAccessLog.

@ParameterizedCompatibleCombinationsTest
@SuppressWarnings("unchecked")
void testAccessLog(HttpServer server, HttpClient client) throws Exception {
    disposableServer = server.handle((req, resp) -> {
        resp.withConnection(conn -> {
            ChannelHandler handler = conn.channel().pipeline().get(NettyPipeline.AccessLogHandler);
            resp.header(NettyPipeline.AccessLogHandler, handler != null ? "FOUND" : "NOT FOUND");
        });
        return resp.send();
    }).accessLog(true).bindNow();
    Appender<ILoggingEvent> mockedAppender = (Appender<ILoggingEvent>) Mockito.mock(Appender.class);
    ArgumentCaptor<LoggingEvent> loggingEventArgumentCaptor = ArgumentCaptor.forClass(LoggingEvent.class);
    Mockito.when(mockedAppender.getName()).thenReturn("MOCK");
    Logger accessLogger = (Logger) LoggerFactory.getLogger("reactor.netty.http.server.AccessLog");
    AtomicReference<String> protocol = new AtomicReference<>();
    try {
        accessLogger.addAppender(mockedAppender);
        client.port(disposableServer.port()).get().uri("/").responseSingle((res, bytes) -> {
            protocol.set(res.responseHeaders().get("x-http2-stream-id") != null ? "2.0" : "1.1");
            return Mono.just(res.responseHeaders().get(NettyPipeline.AccessLogHandler));
        }).as(StepVerifier::create).expectNext("FOUND").expectComplete().verify(Duration.ofSeconds(5));
    } finally {
        Thread.sleep(20);
        Mockito.verify(mockedAppender, Mockito.times(1)).doAppend(loggingEventArgumentCaptor.capture());
        assertThat(loggingEventArgumentCaptor.getAllValues()).hasSize(1);
        LoggingEvent relevantLog = loggingEventArgumentCaptor.getAllValues().get(0);
        assertThat(relevantLog.getFormattedMessage()).contains("GET / HTTP/" + protocol.get() + "\" 200");
        accessLogger.detachAppender(mockedAppender);
    }
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) BaseHttpTest(reactor.netty.BaseHttpTest) Tuple2(reactor.util.function.Tuple2) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Retention(java.lang.annotation.Retention) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) AfterAll(org.junit.jupiter.api.AfterAll) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) ArgumentCaptor(org.mockito.ArgumentCaptor) ByteBuf(io.netty.buffer.ByteBuf) ByteBufFlux(reactor.netty.ByteBufFlux) NettyPipeline(reactor.netty.NettyPipeline) Appender(ch.qos.logback.core.Appender) Duration(java.time.Duration) Schedulers(reactor.core.scheduler.Schedulers) HttpServerConfig(reactor.netty.http.server.HttpServerConfig) Connection(reactor.netty.Connection) MethodSource(org.junit.jupiter.params.provider.MethodSource) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) Predicate(java.util.function.Predicate) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) Mono(reactor.core.publisher.Mono) HttpClientConfig(reactor.netty.http.client.HttpClientConfig) Target(java.lang.annotation.Target) ElementType(java.lang.annotation.ElementType) Mockito(org.mockito.Mockito) Flux(reactor.core.publisher.Flux) AtomicLong(java.util.concurrent.atomic.AtomicLong) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) HttpServer(reactor.netty.http.server.HttpServer) List(java.util.List) Logger(ch.qos.logback.classic.Logger) ChannelHandler(io.netty.channel.ChannelHandler) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) ConnectionProvider(reactor.netty.resources.ConnectionProvider) HttpClient(reactor.netty.http.client.HttpClient) RetentionPolicy(java.lang.annotation.RetentionPolicy) Appender(ch.qos.logback.core.Appender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) ChannelHandler(io.netty.channel.ChannelHandler) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Logger(ch.qos.logback.classic.Logger)

Example 60 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)

Aggregations

Appender (ch.qos.logback.core.Appender)118 Test (org.junit.Test)62 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)51 Logger (ch.qos.logback.classic.Logger)32 LoggerContext (ch.qos.logback.classic.LoggerContext)32 FileAppender (ch.qos.logback.core.FileAppender)27 Logger (org.slf4j.Logger)25 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)21 ArgumentMatcher (org.mockito.ArgumentMatcher)19 AsyncAppender (ch.qos.logback.classic.AsyncAppender)18 File (java.io.File)14 OnMarkerEvaluator (ch.qos.logback.classic.boolex.OnMarkerEvaluator)13 EvaluatorFilter (ch.qos.logback.core.filter.EvaluatorFilter)13 LogstashTcpSocketAppender (net.logstash.logback.appender.LogstashTcpSocketAppender)13 ArrayList (java.util.ArrayList)11 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)11 OutputStreamAppender (ch.qos.logback.core.OutputStreamAppender)10 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)9 DBAppender (ch.qos.logback.classic.db.DBAppender)8 Test (org.junit.jupiter.api.Test)7