removed the manual truncating
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
package io.reflectoring.logging;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import ch.qos.logback.classic.pattern.LoggerConverter;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
|
||||
public class TruncatedLoggerConverter extends LoggerConverter {
|
||||
|
||||
@Override
|
||||
public String convert(ILoggingEvent event) {
|
||||
String maxLengthString = getFirstOption();
|
||||
int maxLength = Integer.parseInt(maxLengthString);
|
||||
String loggerName = super.convert(event);
|
||||
if (loggerName.length() <= maxLength) {
|
||||
return loggerName + generateSpaces(maxLength - loggerName.length());
|
||||
} else {
|
||||
return "..." + loggerName.substring(loggerName.length() - maxLength + 3);
|
||||
}
|
||||
}
|
||||
|
||||
private String generateSpaces(int count) {
|
||||
return Stream.generate(() -> " ").limit(count).collect(Collectors.joining());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package io.reflectoring.logging;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import ch.qos.logback.classic.pattern.ClassicConverter;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
|
||||
public class TruncatedThreadConverter extends ClassicConverter {
|
||||
|
||||
@Override
|
||||
public String convert(ILoggingEvent event) {
|
||||
String maxLengthString = getFirstOption();
|
||||
int maxLength = Integer.parseInt(maxLengthString);
|
||||
String threadName = event.getThreadName();
|
||||
|
||||
if (threadName.length() <= maxLength) {
|
||||
return threadName + generateSpaces(maxLength - threadName.length());
|
||||
} else {
|
||||
return "..." + threadName.substring(threadName.length() - maxLength + 3);
|
||||
}
|
||||
}
|
||||
|
||||
private String generateSpaces(int count) {
|
||||
return Stream.generate(() -> " ").limit(count).collect(Collectors.joining());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
<!-- Appender to log to console -->
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd} | %d{HH:mm:ss.SSS} | %truncatedThread{20} | %5p | %truncatedLogger{25} | %12(ID: %8mdc{id}) | %m%n</pattern>
|
||||
<pattern>%d{yyyy-MM-dd} | %d{HH:mm:ss.SSS} | %-20.20thread | %5p | %-25.25logger{25} | %12(ID: %8mdc{id}) | %m%n</pattern>
|
||||
<charset>utf8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
Reference in New Issue
Block a user