Skip to content

Commit

Permalink
Merge branch 'develop' into ecosystem
Browse files Browse the repository at this point in the history
  • Loading branch information
skjolber authored Jan 20, 2025
2 parents 0ebe70f + f90a5dc commit e59f436
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 36 deletions.
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#Wed Nov 27 11:39:02 UTC 2024
#Sat Jan 18 21:45:38 UTC 2025
org.gradle.jvmargs=-XX\:MaxMetaspaceSize\=512m -Xmx4g
version=4.0.0-SNAPSHOT
version=3.0.3-SNAPSHOT
group=no.entur.logging.cloud
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import no.entur.logging.cloud.logbook.AbstractLogLevelLogstashLogbackSink;
import org.entur.jackson.jsh.AnsiSyntaxHighlight;
import org.entur.jackson.jsh.SyntaxHighlighter;
import org.entur.jackson.jsh.SyntaxHighlightingJsonGenerator;
Expand Down Expand Up @@ -68,27 +69,35 @@ public PrettyPrintingSink(BooleanSupplier logLevelEnabled, BiConsumer<Marker, St
protected void requestMessage(HttpRequest request, StringBuilder messageBuilder) throws IOException {
super.requestMessage(request, messageBuilder);

final String body = request.getBodyAsString();

messageBuilder.append('\n');
writeHeaders(request.getHeaders(), messageBuilder);
writeBody(body, request.getContentType(), messageBuilder);

String contentType = request.getContentType();
boolean isJson = ContentType.isJsonMediaType(contentType);
boolean isXml = isXmlMediaType(contentType);

if(isJson || isXml) {
final String body = request.getBodyAsString();
writeBody(body, contentType, messageBuilder);
}
}

@Override
protected void responseMessage(Correlation correlation, HttpRequest request, HttpResponse response, StringBuilder messageBuilder) throws IOException {
super.responseMessage(correlation, request, response, messageBuilder);

final String body = response.getBodyAsString();

messageBuilder.append('\n');
writeHeaders(response.getHeaders(), messageBuilder);
if(body != null) {
writeBody(body, response.getContentType(), messageBuilder);
}

}
String contentType = response.getContentType();
boolean isJson = ContentType.isJsonMediaType(contentType);
boolean isXml = isXmlMediaType(contentType);

if(isJson || isXml) {
final String body = response.getBodyAsString();
writeBody(body, contentType, messageBuilder);
}
}

private void writeHeaders(final Map<String, List<String>> headers, final StringBuilder output) {
if (headers.isEmpty()) {
Expand Down Expand Up @@ -118,9 +127,11 @@ private void writeHeaders(final Map<String, List<String>> headers, final StringB
}

private void writeBody(final String body, String contentType, final StringBuilder output) {
if (!body.isEmpty()) {
if (body != null && !body.isEmpty()) {
output.append('\n');
if(ContentType.isJsonMediaType(contentType)) {

boolean isJson = ContentType.isJsonMediaType(contentType);
if(isJson) {
output.append(prettyPrint(body));
} else {
output.append(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,6 @@

public abstract class AbstractLogLevelLogstashLogbackSink extends AbstractLogLevelSink {

public static boolean isXmlMediaType(@Nullable final String contentType) {
if (contentType == null) {
return false;
}

String contentTypeWithoutEncoding;
// text/xml;charset=UTF-8
int index = contentType.indexOf(';');
if(index == -1) {
contentTypeWithoutEncoding = contentType;
} else {
contentTypeWithoutEncoding = contentType.substring(0, index).trim();
}

final String lowerCasedContentType = contentTypeWithoutEncoding.toLowerCase();

boolean isApplicationOrText = lowerCasedContentType.startsWith("application/") || lowerCasedContentType.startsWith("text/");
if(!isApplicationOrText) {
return false;
}

return lowerCasedContentType.endsWith("+xml") || lowerCasedContentType.endsWith("/xml");
}

protected final MaxSizeJsonFilter maxSizeJsonFilter;
protected final JsonValidator jsonValidator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,37 @@
import org.slf4j.Marker;
import org.zalando.logbook.*;

import javax.annotation.Nullable;
import java.io.IOException;
import java.util.function.BiConsumer;
import java.util.function.BooleanSupplier;

public abstract class AbstractLogLevelSink implements Sink {

public static boolean isXmlMediaType(@Nullable final String contentType) {
if (contentType == null) {
return false;
}

String contentTypeWithoutEncoding;
// text/xml;charset=UTF-8
int index = contentType.indexOf(';');
if(index == -1) {
contentTypeWithoutEncoding = contentType;
} else {
contentTypeWithoutEncoding = contentType.substring(0, index).trim();
}

final String lowerCasedContentType = contentTypeWithoutEncoding.toLowerCase();

boolean isApplicationOrText = lowerCasedContentType.startsWith("application/") || lowerCasedContentType.startsWith("text/");
if(!isApplicationOrText) {
return false;
}

return lowerCasedContentType.endsWith("+xml") || lowerCasedContentType.endsWith("/xml");
}

protected final BooleanSupplier logLevelEnabled;

protected final BiConsumer<Marker, String> logConsumer;
Expand Down

0 comments on commit e59f436

Please sign in to comment.