Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create one line logging for requested json #1318

Merged
merged 2 commits into from
Jun 15, 2021
Merged
Changes from all commits
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
15 changes: 6 additions & 9 deletions src/main/java/org/prebid/server/log/HttpInteractionLogger.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.prebid.server.log;

import com.fasterxml.jackson.databind.JsonNode;
import io.vertx.core.buffer.Buffer;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.ext.web.RoutingContext;
import lombok.Value;
import org.prebid.server.auction.model.AuctionContext;
import org.prebid.server.json.EncodeException;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.log.model.HttpLogSpec;
import org.prebid.server.settings.model.Account;
Expand Down Expand Up @@ -42,20 +40,19 @@ public void maybeLogOpenrtb2Auction(AuctionContext auctionContext,
logger.info(
"Requested URL: \"{0}\", request body: \"{1}\", response status: \"{2}\", response body: \"{3}\"",
routingContext.request().uri(),
// This creates string without new line and space symbols;
bufferAsString(routingContext.getBody()),
toOneLineString(routingContext.getBodyAsString()),
statusCode,
responseBody);

incLoggedInteractions();
}
}

private String bufferAsString(Buffer buffer) {
private String toOneLineString(String value) {
try {
return mapper.encode(mapper.mapper().convertValue(buffer, JsonNode.class));
} catch (EncodeException | IllegalArgumentException e) {
return buffer.toString();
return mapper.encode(mapper.mapper().readTree(value));
} catch (JsonProcessingException e) {
return String.format("Not parseable JSON passed: %s", value.replaceAll("[\r\n]+", " "));
}
}

Expand Down