ch.qos.logback.classic.spi.LoggingEvent Java Examples

The following examples show how to use ch.qos.logback.classic.spi.LoggingEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: tutorials   Author: eugenp   File: WebClientLoggingIntegrationTest.java    License: MIT License 6 votes vote down vote up
@Test
public void givenNettyHttpClientWithWiretap_whenEndpointIsConsumed_thenRequestAndResponseBodyLogged() {

    reactor.netty.http.client.HttpClient httpClient = HttpClient
      .create()
      .wiretap(true);
    WebClient
      .builder()
      .clientConnector(new ReactorClientHttpConnector(httpClient))
      .build()
      .post()
      .uri(sampleUrl)
      .body(BodyInserters.fromObject(post))
      .exchange()
      .block();

    verify(nettyAppender).doAppend(argThat(argument -> (((LoggingEvent) argument).getFormattedMessage()).contains("00000300")));
}
 
Example #2
Source Project: owasp-security-logging   Author: javabeanz   File: ExcludeClassifiedMarkerFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAppenderMultipleEvent() {
	Marker multi = SecurityMarkers.getMarker(
			SecurityMarkers.SECURITY_AUDIT, SecurityMarkers.CONFIDENTIAL);
	LOGGER.info(multi,
			"This statement contains multiple markers: audit and confidential");

	// Now verify our logging interactions
	verify(mockAppender).doAppend(captorLoggingEvent.capture());

	// Get the logging event from the captor
	LoggingEvent loggingEvent = captorLoggingEvent.getValue();
	System.out.println("testAppender(): loggingEvent: " + loggingEvent);

	// check the filter chain decision for this event
	assertEquals(FilterReply.DENY,
			mockAppender.getFilterChainDecision(loggingEvent));
}
 
Example #3
Source Project: tutorials   Author: eugenp   File: WebClientLoggingIntegrationTest.java    License: MIT License 6 votes vote down vote up
@Test
public void givenNettyHttpClientWithCustomLogger_whenEndpointIsConsumed_thenRequestAndResponseBodyLogged() {

    reactor.netty.http.client.HttpClient httpClient = HttpClient
      .create()
      .tcpConfiguration(
        tc -> tc.bootstrap(
          b -> BootstrapHandlers.updateLogSupport(b, new CustomLogger(HttpClient.class))));
    WebClient
      .builder()
      .clientConnector(new ReactorClientHttpConnector(httpClient))
      .build()
      .post()
      .uri(sampleUrl)
      .body(BodyInserters.fromObject(post))
      .exchange()
      .block();

    verify(nettyAppender).doAppend(argThat(argument -> (((LoggingEvent) argument).getFormattedMessage()).contains(sampleResponseBody)));
}
 
Example #4
Source Project: owasp-security-logging   Author: javabeanz   File: MaskingConverterTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test that masking works for combinations of markers and not just
 * SecurityMarkers.CONFIDENTIAL
 *
 * @see https://github.com/javabeanz/owasp-security-logging/issues/19
 */
@Test
public void markerTest() {
    Marker multiMarker = SecurityMarkers.getMarker(SecurityMarkers.CONFIDENTIAL, SecurityMarkers.SECURITY_FAILURE);

    String ssn = "123-45-6789";
    LOGGER.info(multiMarker, "ssn={}", ssn);

    // Now verify our logging interactions
    verify(mockAppender).doAppend(captorLoggingEvent.capture());

    // Get the logging event from the captor
    final LoggingEvent loggingEvent = captorLoggingEvent.getValue();

    // Check the message being logged is correct
    String layoutMessage = encoder.getLayout().doLayout(loggingEvent);
    assertTrue(layoutMessage.contains("ssn=" + MaskingConverter.MASKED_PASSWORD));
}
 
Example #5
Source Project: owasp-security-logging   Author: javabeanz   File: SecurityMarkerFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAppenderMultipleEvent() {
	Marker multi = SecurityMarkers.getMarker(
			SecurityMarkers.SECURITY_AUDIT, SecurityMarkers.CONFIDENTIAL);
	LOGGER.info(multi,
			"This statement contains multiple markers: security audit and confidential");

	// Now verify our logging interactions
	verify(mockAppender).doAppend(captorLoggingEvent.capture());

	// Get the logging event from the captor
	LoggingEvent loggingEvent = captorLoggingEvent.getValue();
	System.out.println("testAppender(): loggingEvent: " + loggingEvent);

	// check the filter chain decision for this event
	assertEquals(FilterReply.ACCEPT,
			mockAppender.getFilterChainDecision(loggingEvent));
}
 
Example #6
Source Project: owasp-security-logging   Author: javabeanz   File: SecurityMarkerFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAppenderMultipleNonSecurityEvent() {
	Marker multi = SecurityMarkers.getMarker(SecurityMarkers.EVENT_SUCCESS,
			SecurityMarkers.CONFIDENTIAL);
	System.out.println("MARKER: " + multi);
	LOGGER.info(multi,
			"This statement contains multiple markers: event success and confidential");

	// Now verify our logging interactions
	verify(mockAppender).doAppend(captorLoggingEvent.capture());

	// Get the logging event from the captor
	LoggingEvent loggingEvent = captorLoggingEvent.getValue();
	System.out.println("testAppender(): loggingEvent: " + loggingEvent);

	// check the filter chain decision for this event
	assertEquals(FilterReply.DENY,
			mockAppender.getFilterChainDecision(loggingEvent));
}
 
Example #7
Source Project: owasp-security-logging   Author: javabeanz   File: SecurityMarkerFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAppenderSecurityAudit() {
	LOGGER.info(SecurityMarkers.SECURITY_AUDIT,
			"This statement is a security audit");

	// Now verify our logging interactions
	verify(mockAppender).doAppend(captorLoggingEvent.capture());

	// Get the logging event from the captor
	LoggingEvent loggingEvent = captorLoggingEvent.getValue();
	System.out.println("testAppender(): loggingEvent: " + loggingEvent);

	// check the filter chain decision for this event
	assertEquals(FilterReply.ACCEPT,
			mockAppender.getFilterChainDecision(loggingEvent));
}
 
Example #8
Source Project: konker-platform   Author: KonkerLabs   File: KonkerLoggerAppenderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotCaptureTenantAwareLogWhenEventHasNoContextLogLevel(){
    ILoggingEvent logEvent = new LoggingEvent(
            LOG.getName(),
            LOG,
            Level.DEBUG,
            "Test Message",
            null,
            new Object[]{device.toURI()}
    );

    konkerLoggerAppender.append(logEvent);
    Mockito.verify(konkerLoggerAppender, Mockito.never())
            .store(Mockito.any(),
                    Mockito.anyString(),
                    Mockito.anyString(),
                    Mockito.anyString());
}
 
Example #9
Source Project: logging-java   Author: spotify   File: MillisecondPrecisionSyslogStartConverterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldLogContextPropertyHostname() {
  LoggerContext context = new LoggerContext();
  context.putProperty("hostname", HOSTNAME);

  MillisecondPrecisionSyslogStartConverter millisecondPrecisionSyslogStartConverter =
      new MillisecondPrecisionSyslogStartConverter();
  millisecondPrecisionSyslogStartConverter.setContext(context);
  millisecondPrecisionSyslogStartConverter.setOptionList(ImmutableList.of("LOCAL0"));
  millisecondPrecisionSyslogStartConverter.start();

  LoggingEvent event = new LoggingEvent();
  event.setLevel(Level.INFO);
  String message = millisecondPrecisionSyslogStartConverter.convert(event);

  assertTrue(message.contains(HOSTNAME));
}
 
Example #10
Source Project: logback-gelf   Author: osiegmar   File: GelfEncoderTest.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void customLevelNameKey() throws IOException {
    encoder.setIncludeLevelName(true);
    encoder.setLevelNameKey("Severity");
    encoder.start();

    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    final Logger logger = lc.getLogger(LOGGER_NAME);

    final LoggingEvent event = simpleLoggingEvent(logger, null);

    final String logMsg = encodeToStr(event);

    final ObjectMapper om = new ObjectMapper();
    final JsonNode jsonNode = om.readTree(logMsg);
    basicValidation(jsonNode);
    assertEquals("DEBUG", jsonNode.get("_Severity").textValue());
    assertNull(jsonNode.get("_exception"));
}
 
Example #11
Source Project: logback-gelf   Author: osiegmar   File: GelfEncoderTest.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void customLoggerNameKey() throws IOException {
    encoder.setLoggerNameKey("Logger");
    encoder.start();

    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    final Logger logger = lc.getLogger(LOGGER_NAME);

    final LoggingEvent event = simpleLoggingEvent(logger, null);

    final String logMsg = encodeToStr(event);

    final ObjectMapper om = new ObjectMapper();
    final JsonNode jsonNode = om.readTree(logMsg);
    coreValidation(jsonNode);
    assertNotNull(jsonNode.get("_thread_name").textValue());
    assertEquals(LOGGER_NAME, jsonNode.get("_Logger").textValue());
    assertNull(jsonNode.get("_exception"));
}
 
Example #12
Source Project: logback-gelf   Author: osiegmar   File: GelfEncoderTest.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void customThreadNameKey() throws IOException {
    encoder.setThreadNameKey("Thread");
    encoder.start();

    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    final Logger logger = lc.getLogger(LOGGER_NAME);

    final LoggingEvent event = simpleLoggingEvent(logger, null);

    final String logMsg = encodeToStr(event);

    final ObjectMapper om = new ObjectMapper();
    final JsonNode jsonNode = om.readTree(logMsg);
    coreValidation(jsonNode);
    assertNotNull(jsonNode.get("_Thread").textValue());
    assertEquals(LOGGER_NAME, jsonNode.get("_logger_name").textValue());
    assertNull(jsonNode.get("_exception"));
}
 
Example #13
Source Project: logback-gelf   Author: osiegmar   File: GelfEncoderTest.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void numericValueAsNumber() throws IOException {
    encoder.start();

    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    final Logger logger = lc.getLogger(LOGGER_NAME);

    final LoggingEvent event = simpleLoggingEvent(logger, null);

    event.setMDCPropertyMap(ImmutableMap.of("int", "200", "float", "0.00001"));

    final String logMsg = encodeToStr(event);

    final ObjectMapper om = new ObjectMapper();
    final JsonNode jsonNode = om.readTree(logMsg);
    basicValidation(jsonNode);

    assertTrue(logMsg.contains("\"_int\":200"));
    assertTrue(logMsg.contains("\"_float\":0.00001"));
}
 
Example #14
Source Project: logback-gelf   Author: osiegmar   File: GelfEncoderTest.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void multipleMarker() throws IOException {
    encoder.setLoggerNameKey("Logger");
    encoder.start();

    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    final Logger logger = lc.getLogger(LOGGER_NAME);

    final LoggingEvent event = simpleLoggingEvent(logger, null);
    final Marker marker = MarkerFactory.getMarker("FIRST");
    marker.add(MarkerFactory.getMarker("SECOND"));
    event.setMarker(marker);

    final String logMsg = encodeToStr(event);

    final ObjectMapper om = new ObjectMapper();
    final JsonNode jsonNode = om.readTree(logMsg);
    coreValidation(jsonNode);
    assertEquals("FIRST, SECOND", jsonNode.get("_marker").textValue());
}
 
Example #15
Source Project: TranskribusCore   Author: Transkribus   File: LevelRangeFilter.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public FilterReply decide(E eventObject) {
    if (!isStarted()) {
        return FilterReply.NEUTRAL;
    }

    LoggingEvent event = (LoggingEvent) eventObject;

    if (this.levelMin != null && !event.getLevel().isGreaterOrEqual(levelMin)) {
        return DENY;
    }

    if (this.levelMax != null && event.getLevel().toInt() > levelMax.toInt()) {
        return DENY;
    }

    if (acceptOnMatch) {
        return ACCEPT;
    } else {
        return NEUTRAL;
    }
}
 
Example #16
Source Project: pay-publicapi   Author: alphagov   File: RestClientLoggingFilterTest.java    License: MIT License 6 votes vote down vote up
@Test
public void shouldLogRestClientStartEventWithRequestId() {

    String requestId = UUID.randomUUID().toString();
    URI requestUrl = URI.create("/publicapi-request");
    String requestMethod = "GET";
    MultivaluedMap<String, Object> mockHeaders = new MultivaluedHashMap<>();

    when(clientRequestContext.getUri()).thenReturn(requestUrl);
    when(clientRequestContext.getMethod()).thenReturn(requestMethod);
    when(clientRequestContext.getHeaders()).thenReturn(mockHeaders);
    MDC.put(LoggingKeys.MDC_REQUEST_ID_KEY, requestId);

    loggingFilter.filter(clientRequestContext);

    verify(mockAppender, times(1)).doAppend(loggingEventArgumentCaptor.capture());
    List<LoggingEvent> loggingEvents = loggingEventArgumentCaptor.getAllValues();

    assertThat(loggingEvents.get(0).getFormattedMessage(), is(format("[%s] - %s to %s began", requestId, requestMethod, requestUrl)));

}
 
Example #17
Source Project: owasp-security-logging   Author: javabeanz   File: SecurityMarkerFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAppenderSecuritySuccess() {
	LOGGER.info(SecurityMarkers.SECURITY_SUCCESS,
			"This statement is a security success");

	// Now verify our logging interactions
	verify(mockAppender).doAppend(captorLoggingEvent.capture());

	// Get the logging event from the captor
	LoggingEvent loggingEvent = captorLoggingEvent.getValue();
	System.out.println("testAppender(): loggingEvent: " + loggingEvent);

	// check the filter chain decision for this event
	assertEquals(FilterReply.ACCEPT,
			mockAppender.getFilterChainDecision(loggingEvent));
}
 
Example #18
Source Project: tutorials   Author: eugenp   File: WebClientLoggingIntegrationTest.java    License: MIT License 6 votes vote down vote up
@Test
public void givenJettyHttpClient_whenEndpointIsConsumed_thenRequestAndResponseBodyLogged() {
    SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
    org.eclipse.jetty.client.HttpClient httpClient = new org.eclipse.jetty.client.HttpClient(sslContextFactory) {
        @Override
        public Request newRequest(URI uri) {
            Request request = super.newRequest(uri);
            return enhance(request);
        }
    };

    WebClient
      .builder()
      .clientConnector(new JettyClientHttpConnector(httpClient))
      .build()
      .post()
      .uri(sampleUrl)
      .body(BodyInserters.fromObject(post))
      .retrieve()
      .bodyToMono(String.class)
      .block();

    verify(jettyAppender).doAppend(argThat(argument -> (((LoggingEvent) argument).getFormattedMessage()).contains(sampleResponseBody)));
}
 
Example #19
Source Project: owasp-security-logging   Author: javabeanz   File: MaskingConverterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
	String userid = "myId";
	String password = "secret";
	LOGGER.info(SecurityMarkers.CONFIDENTIAL, "userid={}, password='{}'",
			userid, password);

	// Now verify our logging interactions
	verify(mockAppender).doAppend(captorLoggingEvent.capture());

	// Get the logging event from the captor
	final LoggingEvent loggingEvent = captorLoggingEvent.getValue();

	// Check log level is correct
	assertThat(loggingEvent.getLevel(), is(Level.INFO));

	// Check the message being logged is correct
	String layoutMessage = encoder.getLayout().doLayout(loggingEvent);
	assertTrue(layoutMessage.contains("userid="
			+ MaskingConverter.MASKED_PASSWORD + ", password='"
			+ MaskingConverter.MASKED_PASSWORD + "'"));
	assertFalse(layoutMessage.contains("secret"));
}
 
Example #20
Source Project: sofa-registry   Author: sofastack   File: TestAppender.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean containsMessage(String message) {
    for (LoggingEvent loggingEvent : events) {
        if (loggingEvent.getFormattedMessage().contains(message)) {
            return true;
        }
    }

    return false;
}
 
Example #21
Source Project: sofa-registry   Author: sofastack   File: TestAppender.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean containsMessageAndThrowable(String message, Throwable throwable) {
    for (LoggingEvent loggingEvent : events) {
        if (loggingEvent.getFormattedMessage().contains(message)
            && loggingEvent.getThrowableProxy().getMessage().equals(throwable.getMessage())) {
            return true;
        }
    }

    return false;
}
 
Example #22
Source Project: owasp-security-logging   Author: javabeanz   File: ExcludeClassifiedMarkerFilterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRaw() {
	// create a new marker filter
	ExcludeClassifiedMarkerFilter mkt = new ExcludeClassifiedMarkerFilter();
	mkt.setContext(loggerContext);
	mkt.start();

	assertTrue(mkt.isStarted());

	// test a logging event with no markers
	ILoggingEvent nulEvent = new LoggingEvent();
	assertEquals(FilterReply.NEUTRAL, mkt.decide(nulEvent));

	// test a logging event with the CONFIDENTIAL marker
	LoggingEvent confidentialEvent = new LoggingEvent();
	confidentialEvent.setMarker(SecurityMarkers.CONFIDENTIAL);
	assertEquals(FilterReply.DENY, mkt.decide(confidentialEvent));

	// test a logging event with the RESTRICTED marker
	LoggingEvent restrictedEvent = new LoggingEvent();
	restrictedEvent.setMarker(SecurityMarkers.RESTRICTED);
	assertEquals(FilterReply.DENY, mkt.decide(restrictedEvent));

	// test a logging event with the SECRET marker
	LoggingEvent secretEvent = new LoggingEvent();
	secretEvent.setMarker(SecurityMarkers.SECRET);
	assertEquals(FilterReply.DENY, mkt.decide(secretEvent));

	// test a logging event with the TOP_SECRET marker
	LoggingEvent topSecretEvent = new LoggingEvent();
	topSecretEvent.setMarker(SecurityMarkers.TOP_SECRET);
	assertEquals(FilterReply.DENY, mkt.decide(topSecretEvent));

	// test a logging event without the CONFIDENTIAL marker
	LoggingEvent normalEvent = new LoggingEvent();
	normalEvent.setMarker(SecurityMarkers.EVENT_SUCCESS);
	assertEquals(FilterReply.NEUTRAL, mkt.decide(nulEvent));
}
 
Example #23
Source Project: owasp-security-logging   Author: javabeanz   File: ExcludeClassifiedMarkerFilterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAppenderTopSecretEvent() {
	LOGGER.info(SecurityMarkers.TOP_SECRET, "This statement is top secret");

	// Now verify our logging interactions
	verify(mockAppender).doAppend(captorLoggingEvent.capture());

	// Get the logging event from the captor
	LoggingEvent loggingEvent = captorLoggingEvent.getValue();
	System.out.println("testAppender(): loggingEvent: " + loggingEvent);

	// check the filter chain decision for this event
	assertEquals(FilterReply.DENY,
			mockAppender.getFilterChainDecision(loggingEvent));
}
 
Example #24
Source Project: cloudwatch-logback-appender   Author: j256   File: CloudWatchAppender.java    License: ISC License 5 votes vote down vote up
@Override
protected void append(ILoggingEvent loggingEvent) {

	// check wiring
	if (loggingEventQueue == null) {
		if (!warningMessagePrinted) {
			System.err.println(getClass().getSimpleName() + " not wired correctly, ignoring all log messages");
			warningMessagePrinted = true;
		}
		return;
	}

	// skip it if we just went recursive
	Boolean stopped = stopMessagesThreadLocal.get();
	if (stopped == null || !stopped) {
		try {
			if (loggingEvent instanceof LoggingEvent && ((LoggingEvent) loggingEvent).getThreadName() == null) {
				// we need to do this so that the right thread gets set in the event
				((LoggingEvent) loggingEvent).setThreadName(Thread.currentThread().getName());
			}
			if (!loggingEventQueue.offer(loggingEvent, maxQueueWaitTimeMillis, TimeUnit.MILLISECONDS)) {
				if (emergencyAppender != null) {
					emergencyAppender.doAppend(loggingEvent);
				}
			}
		} catch (InterruptedException e) {
			Thread.currentThread().interrupt();
		}
	}
}
 
Example #25
Source Project: owasp-security-logging   Author: javabeanz   File: BaseConverterTest.java    License: Apache License 2.0 5 votes vote down vote up
protected String getLayoutMessage() {
    // Now verify our logging interactions
    verify(mockAppender).doAppend(captorLoggingEvent.capture());
    // Get the logging event from the captor
    final LoggingEvent loggingEvent = captorLoggingEvent.getValue();
    // Check log level is correct
    assertThat(loggingEvent.getLevel(), is(Level.INFO));
    // Check the message being logged is correct
    String layoutMessage = encoder.getLayout().doLayout(loggingEvent);
    System.out.println("layoutMessage: " + layoutMessage);
    return layoutMessage;
}
 
Example #26
Source Project: chaos-monkey-spring-boot   Author: codecentric   File: KillAppAssaultTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp() {
  ch.qos.logback.classic.Logger root =
      (ch.qos.logback.classic.Logger)
          LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
  root.addAppender(mockAppender);

  captorLoggingEvent = ArgumentCaptor.forClass(LoggingEvent.class);
}
 
Example #27
Source Project: owasp-security-logging   Author: javabeanz   File: SecurityMarkerFilterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAppenderNormalEvent() {
	LOGGER.info("This statement is NOT a security event");

	// Now verify our logging interactions
	verify(mockAppender).doAppend(captorLoggingEvent.capture());

	// Get the logging event from the captor
	LoggingEvent loggingEvent = captorLoggingEvent.getValue();
	System.out.println("testAppender(): loggingEvent: " + loggingEvent);

	// check the filter chain decision for this event
	assertEquals(FilterReply.DENY,
			mockAppender.getFilterChainDecision(loggingEvent));
}
 
Example #28
Source Project: owasp-security-logging   Author: javabeanz   File: ExcludeClassifiedMarkerFilterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAppenderSecretEvent() {
	LOGGER.info(SecurityMarkers.SECRET, "This statement is secret");

	// Now verify our logging interactions
	verify(mockAppender).doAppend(captorLoggingEvent.capture());

	// Get the logging event from the captor
	LoggingEvent loggingEvent = captorLoggingEvent.getValue();
	System.out.println("testAppender(): loggingEvent: " + loggingEvent);

	// check the filter chain decision for this event
	assertEquals(FilterReply.DENY,
			mockAppender.getFilterChainDecision(loggingEvent));
}
 
Example #29
Source Project: lambda-monitoring   Author: symphoniacloud   File: MetricPassFilterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBlocksNonMetricMarker() {
    LoggingEvent event = new LoggingEvent();
    event.setMarker(MarkerFactory.getMarker("FOO"));
    MetricPassFilter filter = new MetricPassFilter();
    filter.start();
    assertEquals(FilterReply.DENY, filter.decide(event));
}
 
Example #30
Source Project: tutorials   Author: eugenp   File: MapAppenderUnitTest.java    License: MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    ctx = new LoggerContext();
    ctx.setName("test context");
    ctx.setStatusManager(new BasicStatusManager());
    mapAppender.setContext(ctx);
    mapAppender.setPrefix("prefix");
    event = new LoggingEvent("fqcn", ctx.getLogger("logger"), Level.INFO, "Test message for logback appender", null, new Object[0]);
    ctx.start();
}