Skip to content

Commit

Permalink
Remove redundant log4j-jcl annotations (#2163)
Browse files Browse the repository at this point in the history
  • Loading branch information
vy committed Jan 10, 2024
1 parent a863232 commit b8fb8c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@
*/
package org.apache.logging.log4j.jcl;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.appender.ListAppender;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.test.junit.SetTestProperty;
import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.junit.jupiter.api.Test;

@UsingStatusListener
@SetTestProperty(key = "log4j2.configurationFile", value = "org/apache/logging/log4j/jcl/CallerInformationTest.xml")
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class CallerInformationTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.appender.ListAppender;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.apache.logging.log4j.util.Strings;
import org.junit.jupiter.api.Test;

@UsingStatusListener
class LoggerTest {

@Test
Expand All @@ -39,20 +37,20 @@ void testFactory() {

@Test
@LoggerContextSource("LoggerTest.xml")
void testLog(final LoggerContext loggerContext) {
void testLog(final LoggerContext context) {
final Log logger = LogFactory.getLog("LoggerTest");
logger.debug("Test message");
verify(loggerContext, "o.a.l.l.j.LoggerTest Test message MDC{}" + Strings.LINE_SEPARATOR);
verify(context, "o.a.l.l.j.LoggerTest Test message MDC{}" + Strings.LINE_SEPARATOR);
logger.debug("Exception: ", new NullPointerException("Test"));
verify(loggerContext, "o.a.l.l.j.LoggerTest Exception: MDC{}" + Strings.LINE_SEPARATOR);
verify(context, "o.a.l.l.j.LoggerTest Exception: MDC{}" + Strings.LINE_SEPARATOR);
logger.info("Info Message");
verify(loggerContext, "o.a.l.l.j.LoggerTest Info Message MDC{}" + Strings.LINE_SEPARATOR);
verify(context, "o.a.l.l.j.LoggerTest Info Message MDC{}" + Strings.LINE_SEPARATOR);
logger.info("Info Message {}");
verify(loggerContext, "o.a.l.l.j.LoggerTest Info Message {} MDC{}" + Strings.LINE_SEPARATOR);
verify(context, "o.a.l.l.j.LoggerTest Info Message {} MDC{}" + Strings.LINE_SEPARATOR);
}

private static void verify(final LoggerContext loggerContext, final String expected) {
final ListAppender listApp = loggerContext.getConfiguration().getAppender("List");
private static void verify(final LoggerContext context, final String expected) {
final ListAppender listApp = context.getConfiguration().getAppender("List");
final List<String> events = listApp.getMessages();
assertThat(events).hasSize(1).containsExactly(expected);
listApp.clear();
Expand Down

0 comments on commit b8fb8c8

Please sign in to comment.