Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing message field to be null to match SLF4J behavior #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/uk/org/lidalia/slf4jtest/LoggingEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private LoggingEvent(
this.mdc = ImmutableMap.copyOf(mdc);
this.marker = checkNotNull(marker);
this.throwable = checkNotNull(throwable);
this.message = checkNotNull(message);
this.message = message;
this.arguments = from(asList(arguments)).transform(TO_NON_NULL_VALUE).toList();
}

Expand All @@ -339,7 +339,7 @@ public Object apply(final Object input) {
@Identity private final ImmutableMap<String, String> mdc;
@Identity private final Optional<Marker> marker;
@Identity private final Optional<Throwable> throwable;
@Identity private final String message;
@Identity /* @Nullable */ private final String message;
@Identity private final ImmutableList<Object> arguments;

private final Optional<TestLogger> creatingLogger;
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/uk/org/lidalia/slf4jtest/LoggingEventTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -528,6 +529,12 @@ public void nullArgument() {
assertThat(event, is(new LoggingEvent(level, "message with null arg", absent(), absent())));
}

@Test
public void nullMessage() {
LoggingEvent event = new LoggingEvent(level, null);
assertThat(event.getMessage(), nullValue());
}

@After
public void reset() {
TestLoggerFactory.reset();
Expand Down