Skip to content

Commit 414d91a

Browse files
authored
Merge pull request #38 from newrelic/add-test-for-logback-custom-args
Add test for logback custom args
2 parents 0a46280 + f8f56ff commit 414d91a

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

logback/src/test/java/com/newrelic/logging/logback/NewRelicLogbackTests.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ void shouldAppendCallerDataToJsonCorrectly() throws Throwable {
7676
thenTheCallerDataIsInTheMessage();
7777
}
7878

79-
8079
@Test
8180
@Timeout(3)
8281
void shouldAppendErrorDataCorrectly() throws Throwable {
@@ -88,6 +87,17 @@ void shouldAppendErrorDataCorrectly() throws Throwable {
8887
thenTheExceptionDataIsInTheMessage();
8988
}
9089

90+
@Test
91+
@Timeout(3)
92+
void shouldAppendCustomArgsToJsonCorrectly() throws Throwable {
93+
givenMockAgentData();
94+
givenARedirectedAppender();
95+
givenALoggingEventWithCustomArgs();
96+
whenTheEventIsAppended();
97+
thenJsonLayoutWasUsed();
98+
thenTheCustomArgsAreInTheMessage();
99+
}
100+
91101
private void givenMockAgentData() {
92102
Agent mockAgent = Mockito.mock(Agent.class);
93103
Mockito.when(mockAgent.getLinkingMetadata()).thenReturn(ImmutableMap.of("some.key", "some.value"));
@@ -114,6 +124,16 @@ private void givenALoggingEventWithCallerData() {
114124
event.setCallerData(new StackTraceElement[] { new Exception().getStackTrace()[0] });
115125
}
116126

127+
private void givenALoggingEventWithCustomArgs() {
128+
givenALoggingEvent();
129+
CustomArgument customArgument1 = new CustomArgument("customKey1", "customValue1");
130+
CustomArgument customArgument2 = new CustomArgument("customKey2", "customValue2");
131+
Object[] customArgs = new Object[2];
132+
customArgs[0] = customArgument1;
133+
customArgs[1] = customArgument2;
134+
event.setArgumentArray(customArgs);
135+
}
136+
117137
private void givenARedirectedAppender() {
118138
NewRelicEncoder encoder = new NewRelicEncoder();
119139
encoder.start();
@@ -172,6 +192,13 @@ private void thenTheExceptionDataIsInTheMessage() throws Throwable {
172192
);
173193
}
174194

195+
private void thenTheCustomArgsAreInTheMessage() throws Throwable {
196+
LogAsserts.assertFieldValues(
197+
getOutput(),
198+
ImmutableMap.of("customKey1", "customValue1", "customKey2", "customValue2")
199+
);
200+
}
201+
175202
private String getOutput() throws IOException {
176203
if (output == null) {
177204
output = bufferedReader.readLine() + "\n";

0 commit comments

Comments
 (0)