Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add lineSeparator field instead of inline
  • Loading branch information
Damien Ferey committed May 18, 2022
commit ea439d4c9505dfbc2ca7650424c56e65db81d09b
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public class ShortenedThrowableConverter extends ThrowableHandlingConverter {
private static final int OPTION_INDEX_SHORTENED_CLASS_NAME = 1;
private static final int OPTION_INDEX_MAX_LENGTH = 2;

/** String sequence to use to delimit lines instead of {@link CoreConstants#LINE_SEPARATOR} when {@link #inline} is active */
public static final String INLINE_SEPARATOR = "\\n";
/** String sequence to use to delimit lines instead of {@link CoreConstants#LINE_SEPARATOR} when inline is active */
public static final String DEFAULT_INLINE_SEPARATOR = "\\n";

private AtomicInteger errorCount = new AtomicInteger();

Expand Down Expand Up @@ -165,10 +165,8 @@ public class ShortenedThrowableConverter extends ThrowableHandlingConverter {
*/
private boolean inlineHash;

/**
* True to use "\\n" sequence instead of {@link CoreConstants#LINE_SEPARATOR}
*/
private boolean inline;
/** line delimiter */
private String lineSeparator = CoreConstants.LINE_SEPARATOR;

private StackElementFilter stackElementFilter;

Expand Down Expand Up @@ -236,7 +234,7 @@ private void parseOptions() {
} else if (OPTION_VALUE_INLINE_HASH.equals(option)) {
setInlineHash(true);
} else if (OPTION_VALUE_INLINE_STACK.equals(option)) {
setInline(true);
setLineSeparator(DEFAULT_INLINE_SEPARATOR);
} else {
@SuppressWarnings("rawtypes")
Map evaluatorMap = (Map) getContext().getObject(CoreConstants.EVALUATOR_MAP);
Expand Down Expand Up @@ -301,10 +299,12 @@ public String convert(ILoggingEvent event) {
return builder.toString();
}

private String getLineSeparator() {
return isInline()
? INLINE_SEPARATOR
: CoreConstants.LINE_SEPARATOR;
public String getLineSeparator() {
return lineSeparator;
}

public void setLineSeparator(String lineSeparator) {
this.lineSeparator = lineSeparator;
}

/**
Expand Down Expand Up @@ -625,14 +625,6 @@ public void setInlineHash(boolean inlineHash) {
this.inlineHash = inlineHash;
}

public boolean isInline() {
return inline;
}

public void setInline(boolean inlineHash) {
this.inline = inlineHash;
}

protected void setStackHasher(StackHasher stackHasher) {
this.stackHasher = stackHasher;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public void testOptions() throws EvaluationException {
assertThat(converter.getShortenedClassNameLength()).isEqualTo(ShortenedThrowableConverter.FULL_CLASS_NAME_LENGTH);
assertThat(converter.getMaxLength()).isEqualTo(ShortenedThrowableConverter.FULL_MAX_LENGTH);
assertThat(converter.isRootCauseFirst()).isTrue();
assertThat(converter.isInline()).isFalse();
assertThat(converter.getLineSeparator()).isEqualTo(CoreConstants.LINE_SEPARATOR);
assertThat(converter.getEvaluators().get(0)).isEqualTo(evaluator);
assertThat(converter.getExcludes().get(0)).isEqualTo("regex");

Expand All @@ -326,7 +326,7 @@ public void testOptions() throws EvaluationException {
assertThat(converter.getMaxDepthPerThrowable()).isEqualTo(ShortenedThrowableConverter.SHORT_MAX_DEPTH_PER_THROWABLE);
assertThat(converter.getShortenedClassNameLength()).isEqualTo(ShortenedThrowableConverter.SHORT_CLASS_NAME_LENGTH);
assertThat(converter.getMaxLength()).isEqualTo(ShortenedThrowableConverter.SHORT_MAX_LENGTH);
assertThat(converter.isInline()).isTrue();
assertThat(converter.getLineSeparator()).isEqualTo(ShortenedThrowableConverter.DEFAULT_INLINE_SEPARATOR);

// test numeric values
converter.setOptionList(Arrays.asList("1", "2", "3"));
Expand Down Expand Up @@ -435,7 +435,7 @@ public void test_inline_stack() {
// GIVEN
StackHasher mockedHasher = Mockito.mock(StackHasher.class);
ShortenedThrowableConverter converter = new ShortenedThrowableConverter();
converter.setInline(true);
converter.setLineSeparator(ShortenedThrowableConverter.DEFAULT_INLINE_SEPARATOR);
converter.setRootCauseFirst(true);
converter.start();
converter.setStackHasher(mockedHasher);
Expand All @@ -446,7 +446,7 @@ public void test_inline_stack() {
// THEN
// verify we have expected stack hashes inlined
assertThat(formatted).doesNotContain(CoreConstants.LINE_SEPARATOR);
assertThat(formatted).contains(ShortenedThrowableConverter.INLINE_SEPARATOR);
assertThat(formatted).contains(ShortenedThrowableConverter.DEFAULT_INLINE_SEPARATOR);
}
}

Expand Down