-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1857 from newrelic/log-caused-by
Add "caused by" section(s) when forwarding logs
- Loading branch information
Showing
10 changed files
with
313 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...he-log4j-1/src/test/java/com/nr/agent/instrumentation/log4j1/Log4j1ExceptionUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.nr.agent.instrumentation.log4j1; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class Log4j1ExceptionUtilTest { | ||
@Test | ||
public void getErrorStack_withThrowable_generatesFullStacktrace() { | ||
assertFalse(Log4j1ExceptionUtil.getErrorStack(createTestException()).contains("caused by: java.lang.Exception: inner exception")); | ||
|
||
assertTrue(Log4j1ExceptionUtil.getErrorStack(createTestExceptionWithCausedBy()).contains("caused by: java.lang.Exception: inner exception")); | ||
} | ||
|
||
@Test | ||
public void getErrorStack_withNullThrowable_returnsNull() { | ||
assertNull(Log4j1ExceptionUtil.getErrorStack(null)); | ||
} | ||
|
||
@Test | ||
public void getErrorMessage_withThrowable_returnsErrorMessage() { | ||
assertEquals("test exception", Log4j1ExceptionUtil.getErrorMessage(createTestException())); | ||
} | ||
|
||
@Test | ||
public void getErrorMessage_withNullThrowable_returnsNull() { | ||
assertNull(Log4j1ExceptionUtil.getErrorMessage(null)); | ||
} | ||
|
||
@Test | ||
public void getErrorClass_withThrowable_returnsErrorMessage() { | ||
assertEquals("java.lang.Exception", Log4j1ExceptionUtil.getErrorClass(createTestException())); | ||
} | ||
|
||
@Test | ||
public void getErrorClass_withNullThrowable_returnsNull() { | ||
assertNull(Log4j1ExceptionUtil.getErrorClass(null)); | ||
} | ||
|
||
private Exception createTestException() { | ||
return new Exception("test exception"); | ||
} | ||
|
||
private Exception createTestExceptionWithCausedBy() { | ||
return new Exception("test exception", new Exception("inner exception")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.