Skip to content

Commit 4fbdaae

Browse files
Remove org.apacha.commons:commons-lang3
Replace StringUtils.isBlank by custom implementations. Signed-off-by: Karsten Schnitter <k.schnitter@sap.com>
1 parent ce794a9 commit 4fbdaae

File tree

6 files changed

+24
-20
lines changed

6 files changed

+24
-20
lines changed

cf-java-logging-support-core/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
<version>${logback.version}</version>
2222
<scope>test</scope>
2323
</dependency>
24-
25-
<dependency>
26-
<groupId>org.apache.commons</groupId>
27-
<artifactId>commons-lang3</artifactId>
28-
<version>3.19.0</version>
29-
</dependency>
3024
</dependencies>
3125

3226
<parent>

cf-java-logging-support-core/src/main/java/com/sap/hcp/cf/logging/common/converter/LineWriter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.sap.hcp.cf.logging.common.converter;
22

3-
import org.apache.commons.lang3.StringUtils;
4-
53
import java.io.IOException;
64
import java.io.StringWriter;
75
import java.io.Writer;
@@ -12,7 +10,7 @@ public class LineWriter extends Writer {
1210

1311
StringWriter sw = new StringWriter();
1412

15-
private List<String> lines = new LinkedList<String>();
13+
private final List<String> lines = new LinkedList<String>();
1614

1715
public LineWriter() {
1816
}
@@ -26,7 +24,7 @@ public List<String> getLines() {
2624
*/
2725
@Override
2826
public void write(String str, int off, int len) {
29-
if (StringUtils.isNotBlank(str)) {
27+
if (str != null && !str.isBlank()) {
3028
lines.add(str);
3129
}
3230
}

cf-java-logging-support-log4j2/src/main/java/com/sap/hcp/cf/log4j2/filter/DynamicLevelPrefixLoggerFilter.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.sap.hcp.cf.log4j2.filter;
22

33
import com.sap.hcp.cf.logging.common.helper.DynamicLogLevelHelper;
4-
import org.apache.commons.lang3.StringUtils;
54
import org.apache.logging.log4j.Level;
65
import org.apache.logging.log4j.Marker;
76
import org.apache.logging.log4j.core.LogEvent;
@@ -32,7 +31,11 @@ public Result filter(LogEvent event) {
3231

3332
private Level getDynamicLevel(LogEvent event) {
3433
String logLevel = getContextValue(event, DynamicLogLevelHelper.MDC_DYNAMIC_LOG_LEVEL_KEY);
35-
return StringUtils.isNotBlank(logLevel) ? Level.getLevel(logLevel) : null;
34+
return isNotBlank(logLevel) ? Level.getLevel(logLevel) : null;
35+
}
36+
37+
private static boolean isNotBlank(String string) {
38+
return string != null && !string.isBlank();
3639
}
3740

3841
private String getContextValue(LogEvent event, String key) {
@@ -54,7 +57,7 @@ private Result filter(Level level, Level dynamicLevel, String loggerFqcn, String
5457
}
5558

5659
private boolean checkPackages(String loggerFqcn, String logLevelPackages) {
57-
if (StringUtils.isNotBlank(logLevelPackages)) {
60+
if (isNotBlank(logLevelPackages)) {
5861
for (String current: logLevelPackages.split(",")) {
5962
if (loggerFqcn.startsWith(current)) {
6063
return true;
@@ -84,7 +87,7 @@ public Result filter(final Logger logger, final Level level, final Marker marker
8487

8588
private Level getMdcLevel() {
8689
String mdcLevel = MDC.get(DynamicLogLevelHelper.MDC_DYNAMIC_LOG_LEVEL_KEY);
87-
return StringUtils.isNotBlank(mdcLevel) ? Level.getLevel(mdcLevel) : null;
90+
return isNotBlank(mdcLevel) ? Level.getLevel(mdcLevel) : null;
8891
}
8992

9093
private String getMdcPackages() {

cf-java-logging-support-log4j2/src/main/java/com/sap/hcp/cf/log4j2/layout/suppliers/BaseFieldSupplier.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.sap.hcp.cf.log4j2.converter.api.Log4jContextFieldSupplier;
44
import com.sap.hcp.cf.logging.common.Defaults;
55
import com.sap.hcp.cf.logging.common.Fields;
6-
import org.apache.commons.lang3.StringUtils;
76
import org.apache.logging.log4j.core.LogEvent;
87

98
import java.time.Instant;
@@ -32,13 +31,17 @@ public Map<String, Object> map(LogEvent event) {
3231
if (event.getThrown() != null) {
3332
Throwable throwable = event.getThrown();
3433
fields.put(Fields.EXCEPTION_TYPE, throwable.getClass().getName());
35-
if (StringUtils.isNotBlank(throwable.getMessage())) {
34+
if (isNotBlank(throwable.getMessage())) {
3635
fields.put(Fields.EXCEPTION_MESSAGE, throwable.getMessage());
3736
}
3837
}
3938
return fields;
4039
}
4140

41+
private static boolean isNotBlank(String string) {
42+
return string != null && !string.isBlank();
43+
}
44+
4245
private String getIsoTs(LogEvent event) {
4346
org.apache.logging.log4j.core.time.Instant instant = event.getInstant();
4447
return Instant.ofEpochSecond(instant.getEpochSecond(), instant.getNanoOfSecond()).toString();

cf-java-logging-support-logback/src/main/java/com/sap/hcp/cf/logback/encoder/BaseFieldSupplier.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.sap.hcp.cf.logging.common.Defaults;
77
import com.sap.hcp.cf.logging.common.Fields;
88
import com.sap.hcp.cf.logging.common.Markers;
9-
import org.apache.commons.lang3.StringUtils;
109

1110
import java.time.Instant;
1211
import java.util.HashMap;
@@ -34,13 +33,17 @@ public Map<String, Object> map(ILoggingEvent event) {
3433
if (event.getThrowableProxy() != null && event.getThrowableProxy() instanceof ThrowableProxy) {
3534
Throwable throwable = ((ThrowableProxy) event.getThrowableProxy()).getThrowable();
3635
fields.put(Fields.EXCEPTION_TYPE, throwable.getClass().getName());
37-
if (StringUtils.isNotBlank(throwable.getMessage())) {
36+
if (isNotBlank(throwable.getMessage())) {
3837
fields.put(Fields.EXCEPTION_MESSAGE, throwable.getMessage());
3938
}
4039
}
4140
return fields;
4241
}
4342

43+
private static boolean isNotBlank(String string) {
44+
return string != null && !string.isBlank();
45+
}
46+
4447
private String now() {
4548
Instant now = Instant.now();
4649
long timestamp = now.getEpochSecond() * 1_000_000_000L + now.getNano();

cf-java-logging-support-logback/src/main/java/com/sap/hcp/cf/logback/filter/DynamicLevelPrefixLoggerTurboFilter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import ch.qos.logback.classic.turbo.TurboFilter;
66
import ch.qos.logback.core.spi.FilterReply;
77
import com.sap.hcp.cf.logging.common.helper.DynamicLogLevelHelper;
8-
import org.apache.commons.lang3.StringUtils;
98
import org.slf4j.MDC;
109
import org.slf4j.Marker;
1110

@@ -23,7 +22,7 @@ public FilterReply decide(final Marker marker, final Logger logger, final Level
2322

2423
private boolean checkPackages(final Logger logger) {
2524
final String logLevelPackages = MDC.get(DynamicLogLevelHelper.MDC_DYNAMIC_LOG_LEVEL_PREFIXES);
26-
if (StringUtils.isNotBlank(logLevelPackages)) {
25+
if (isNotBlank(logLevelPackages)) {
2726
for (String current: logLevelPackages.split(",")) {
2827
if (logger.getName().startsWith(current)) {
2928
return true;
@@ -33,4 +32,8 @@ private boolean checkPackages(final Logger logger) {
3332
return false;
3433
}
3534

35+
private static boolean isNotBlank(String string) {
36+
return string != null && !string.isBlank();
37+
}
38+
3639
}

0 commit comments

Comments
 (0)