π Wire Telemetry Governance, PII Redaction & Log Noise Suppression
During automated API testing, complete visibility into the HTTP wire transaction is vital for triaging broken contracts, tracking malformed payloads, and debugging gateway rejections. However, unconstrained logging with log().all() across hundreds of continuous integration test suites floods build runners with gigabytes of noisy console clutter while dangerously leaking sensitive credentialsβincluding Bearer tokens, API secret keys, passwords, and PII cookiesβinto persistent build logs. REST Assured's Logging & LogConfig Architecture provides fine-grained control over wire telemetry. By applying selective logging scopes (such as log().parameters() or log().uri()), enforcing conditional failure output with log().ifValidationFails(), enabling cryptographic header and cookie blacklisting via LogConfig.blacklistHeaders(), and redirecting transcripts into dedicated audit file streams, automation engineers strike the perfect balance between zero-noise CI pipelines, strict security compliance, and comprehensive diagnostic root-cause analysis.
REST ASSURED LOGGING SUBSYSTEM & BLACKLISTING TOPOGRAPHY:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β OUTBOUND WIRE TRANSMISSION (Given Phase) β
β POST /v1/auth/login | Headers: Authorization, X-API-Key | Body: {"secret":"Pass#2026"} β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LOGCONFIG SANITIZATION & INTERCEPTION ENGINE β
β βββ 1. Header Blacklist Filter: Matched "Authorization", "X-API-Key" βββΊ Replace with [REDACTED] β
β βββ 2. Cookie Blacklist Filter: Matched "JSESSIONID", "session_token" βββΊ Replace with [REDACTED]β
β βββ 3. Pretty-Printer Formatter: Indents compact raw JSON into readable formatted text β
β βββ 4. Stream Router: Dispatches sanitized stream to console (System.out) or PrintStream File β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββ
βΌ βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββ
β MODE A: SELECTIVE LOGGING β β MODE B: CONDITIONAL FAILURE TRIAGE β
ββββββββββββββββββββββββββββββββββββββββββββββββ€ βββββββββββββββββββββββββββββββββββββββββββββββββββ€
β .log().params() βββΊ Logs only parameters β β .log().ifValidationFails() β
β .log().headers() βββΊ Logs sanitized headers β β β’ If Assertions Pass: SILENT (Zero clutter) β
β .log().body() βββΊ Logs indented payload β β β’ If Assertions Fail: Dumps full sanitized β
β .log().uri() βββΊ Logs final target URL β β outbound request & inbound response envelope β
ββββββββββββββββββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββ
log().params(), log().headers(), log().body(), and log().status()βto observe specific HTTP message components.
package com.nikita.restassured.logging;
import io.restassured.http.ContentType;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
public class SelectiveLoggingScopeTest {
private static final String BASE_URI = "https://staging-api.nikita-infotech.com/v1";
@Test(description = "Demonstrate selective logging: log only query parameters and response status")
public void testSelectiveParamsAndStatusLogging() {
given()
.baseUri(BASE_URI)
.queryParam("academicTrack", "ENTERPRISE_AUTOMATION")
.queryParam("page", 1)
.queryParam("limit", 10)
// Log ONLY request parameters (ignoring headers, cookies, and connection details)
.log().parameters()
.when()
.get("/students")
.then()
// Log ONLY response status line and code (suppressing full body dump)
.log().status()
.statusCode(200)
.body("status", equalTo("SUCCESS"));
System.out.println("[β] Executed test with isolated parameter and status logging.");
}
@Test(description = "Demonstrate selective logging: log only JSON body payloads")
public void testSelectiveBodyOnlyLogging() {
Map<String, Object> payload = new HashMap<>();
payload.put("fullName", "Nikita Sharma");
payload.put("enrolledCredits", 16);
given()
.baseUri(BASE_URI)
.contentType(ContentType.JSON)
.body(payload)
// Log ONLY outbound serialized body
.log().body()
.when()
.post("/students")
.then()
// Log ONLY inbound response body
.log().body()
.statusCode(201);
System.out.println("[β] Executed test with body-only wire inspection.");
}
}
log().ifValidationFails() on both request and response envelopes, ensuring tests remain completely silent during normal runs but dump full wire traces when assertions fail.
package com.nikita.restassured.logging;
import io.restassured.http.ContentType;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
public class ConditionalFailureLoggingTest {
private static final String BASE_URI = "https://staging-api.nikita-infotech.com/v1";
@Test(description = "Passing test remains completely silent: zero console noise in CI")
public void testPassingScenarioRemainsSilent() {
given()
.baseUri(BASE_URI)
.header("X-Tenant-Key", "MAHARASHTRA_PUNE_01")
// Silent during pass; dumps full request packet only if assertions fail:
.log().ifValidationFails()
.when()
.get("/health")
.then()
// Silent during pass; dumps full response packet only if assertions fail:
.log().ifValidationFails()
.statusCode(200)
.body("status", equalTo("UP"));
System.out.println("[β] Test passed silently without printing raw wire packets.");
}
@Test(description = "Demonstrate conditional dump triggered when assertion expectations fail")
public void testSimulateAssertionFailureDump() {
// To observe: this test deliberately expects status 201 on a GET returning 200
// log().ifValidationFails() will automatically dump both request and response envelopes!
given()
.baseUri(BASE_URI)
.queryParam("track", "ENTERPRISE_AUTOMATION")
.log().ifValidationFails()
.when()
.get("/students")
.then()
.log().ifValidationFails()
.statusCode(200); // Set to 200 for suite pass, or 201 to view full diagnostic dump
System.out.println("[β] Conditional logging verified.");
}
}
LogConfig.blacklistHeaders() to redact sensitive headers like Authorization, X-API-Key, and Proxy-Authorization from console and reporting output.
package com.nikita.restassured.logging;
import io.restassured.config.LogConfig;
import io.restassured.config.RestAssuredConfig;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
public class HeaderBlacklistingTest {
private static final String BASE_URI = "https://staging-api.nikita-infotech.com/v1";
@Test(description = "Redact sensitive Authorization and API Key headers from console logs")
public void testBlacklistSensitiveHeaders() {
Set<String> sensitiveHeaders = new HashSet<>(Arrays.asList(
"Authorization",
"X-API-Key",
"X-Admin-Token"
));
// Configure LogConfig to blacklist sensitive headers:
RestAssuredConfig secureLoggingConfig = RestAssuredConfig.config()
.logConfig(LogConfig.logConfig()
.blacklistHeaders(sensitiveHeaders));
given()
.config(secureLoggingConfig)
.baseUri(BASE_URI)
.header("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.SECRET_TOKEN_DATA")
.header("X-API-Key", "live_secret_key_88219_pune_enterprise")
.header("X-Public-Client", "Automation-Worker")
// Dump all headers to prove sensitive tokens are masked:
.log().headers()
.when()
.get("/students/STU-88219/grades")
.then()
.statusCode(200)
.body("status", equalTo("SUCCESS"));
System.out.println("[β] Request executed with sensitive headers successfully blacklisted in logs.");
}
}
LogConfig.blacklistCookies() to sanitize session cookies like JSESSIONID, SESSION_AFFINITY_ID, and remember_me tokens.
package com.nikita.restassured.logging;
import io.restassured.config.LogConfig;
import io.restassured.config.RestAssuredConfig;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
public class CookieBlacklistingTest {
private static final String BASE_URI = "https://staging-api.nikita-infotech.com/v1";
@Test(description = "Redact session tracking and security cookies from console logs")
public void testBlacklistSessionCookies() {
Set<String> blacklistedCookies = new HashSet<>(Arrays.asList(
"JSESSIONID",
"SESSION_AFFINITY_ID",
"remember_token"
));
// Configure LogConfig to blacklist cookies:
RestAssuredConfig secureConfig = RestAssuredConfig.config()
.logConfig(LogConfig.logConfig()
.blacklistCookies(blacklistedCookies));
given()
.config(secureConfig)
.baseUri(BASE_URI)
.cookie("JSESSIONID", "sess_prod_secure_4f8a10c9bf12_node1")
.cookie("SESSION_AFFINITY_ID", "aff_99412_pune")
.cookie("ui_theme", "dark_mode")
// Dump cookies to prove sensitive session values are redacted:
.log().cookies()
.when()
.get("/portal/dashboard")
.then()
.statusCode(200)
.body("status", equalTo("AUTHENTICATED"));
System.out.println("[β] Session cookies sanitized cleanly in output stream.");
}
}
enablePrettyPrinting(true) in LogConfig to automatically format compacted single-line JSON responses into indented, readable structures.
package com.nikita.restassured.logging;
import io.restassured.config.LogConfig;
import io.restassured.config.RestAssuredConfig;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
public class PrettyPrintingLoggingTest {
private static final String BASE_URI = "https://staging-api.nikita-infotech.com/v1";
@Test(description = "Verify JSON responses format with clean indentation via enablePrettyPrinting")
public void testPrettyPrintedPayloadFormatting() {
// Enforce pretty-printing explicitly in LogConfig
RestAssuredConfig prettyConfig = RestAssuredConfig.config()
.logConfig(LogConfig.logConfig()
.enablePrettyPrinting(true));
given()
.config(prettyConfig)
.baseUri(BASE_URI)
.pathParam("studentId", "STU-88219")
.when()
.get("/students/{studentId}")
.then()
// Prints indented JSON rather than a minified single line:
.log().body()
.statusCode(200);
System.out.println("[β] Logged formatted JSON body cleanly.");
}
}
LogConfig.defaultStream() to redirect REST Assured logs to external log files (e.g. target/rest-assured-wire.log) or in-memory byte streams for diagnostic archiving.
package com.nikita.restassured.logging;
import io.restassured.config.LogConfig;
import io.restassured.config.RestAssuredConfig;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import static io.restassured.RestAssured.given;
public class FileRedirectLoggingTest {
private static final String BASE_URI = "https://staging-api.nikita-infotech.com/v1";
@Test(description = "Redirect wire logs to target file instead of polluting stdout console")
public void testRedirectLogsToExternalFile() throws IOException {
File logFile = new File("target/api-wire-audit.log");
logFile.getParentFile().mkdirs();
// Direct logging to custom FileOutputStream PrintStream:
try (PrintStream fileStream = new PrintStream(new FileOutputStream(logFile, false))) {
RestAssuredConfig fileLoggingConfig = RestAssuredConfig.config()
.logConfig(LogConfig.logConfig()
.defaultStream(fileStream)
.enablePrettyPrinting(true));
given()
.config(fileLoggingConfig)
.baseUri(BASE_URI)
.log().all() // Redirected to target/api-wire-audit.log
.when()
.get("/students")
.then()
.log().all() // Redirected to target/api-wire-audit.log
.statusCode(200);
}
System.out.println("[*] Wire transcript written to file: " + logFile.getAbsolutePath());
Assert.assertTrue(logFile.exists() && logFile.length() > 0, "Log file must contain wire output!");
}
}
LogConfig sanitizers, header blacklists, and failure-only triggers into a shared RequestSpecBuilder template.
package com.nikita.restassured.logging;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.config.LogConfig;
import io.restassured.config.RestAssuredConfig;
import io.restassured.filter.log.LogDetail;
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.HashSet;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
public class GlobalLoggingSpecTest {
private static RequestSpecification enterpriseLoggingSpec;
@BeforeSuite
public void setupGlobalLoggingSpecification() {
// Universal secure logging configuration
RestAssuredConfig secureConfig = RestAssuredConfig.config()
.logConfig(LogConfig.logConfig()
.blacklistHeaders(new HashSet<>(Arrays.asList("Authorization", "X-Api-Key", "Cookie")))
.blacklistCookies(new HashSet<>(Arrays.asList("JSESSIONID", "session_token")))
.enablePrettyPrinting(true));
enterpriseLoggingSpec = new RequestSpecBuilder()
.setConfig(secureConfig)
.setBaseUri("https://staging-api.nikita-infotech.com")
.setBasePath("/v1")
.setContentType(ContentType.JSON)
// Default: log request and response only on assertion failures:
.log(LogDetail.URI)
.build();
System.out.println("[*] Enterprise Logging & Blacklisting Specification initialized.");
}
@Test(description = "Verify test inheriting enterprise logging rules from shared specification")
public void testInheritedLoggingRules() {
given()
.spec(enterpriseLoggingSpec)
.header("Authorization", "Bearer SUPER_SECRET_ENTERPRISE_TOKEN")
.pathParam("studentId", "STU-88219")
.when()
.get("/students/{studentId}")
.then()
.statusCode(200)
.body("status", equalTo("SUCCESS"));
System.out.println("[β] Executed request using global enterprise logging specification.");
}
}
java.io.IOException: Stream Closed on multi-read responses, managing memory usage during large binary downloads, and avoiding unclosed PrintStream file locks.
package com.nikita.restassured.logging;
import io.restassured.response.Response;
import org.testng.Assert;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
public class LoggingPitfallsTriageTest {
private static final String BASE_URI = "https://staging-api.nikita-infotech.com/v1";
// ==========================================================================
// PITFALL 1: DUMPING BINARY / MULTIPART FILES TO CONSOLE VIA log().body()
// Dumping a 15MB PDF to console prints binary garbage and crashes build runners!
// SOLUTION: Use log().headers() or log().status() on binary endpoints.
// ==========================================================================
@Test(description = "Verify safe selective logging on binary endpoints without dumping binary bytes")
public void testSafeBinaryEndpointLogging() {
Response response = given()
.baseUri(BASE_URI)
.pathParam("docId", "DOC-88219")
// Log only URI and headers: NEVER call .log().body() on binary endpoints!
.log().uri()
.log().headers()
.when()
.get("/documents/{docId}/download")
.then()
// Log status and headers only:
.log().status()
.log().headers()
.statusCode(200)
.extract().response();
// Extract raw byte array without logging garbage to console:
byte[] binaryData = response.asByteArray();
System.out.println("[*] Downloaded binary payload safely: " + binaryData.length + " bytes.");
Assert.assertTrue(binaryData.length > 0);
}
}
LOGGING & BLACKLISTING SPECIFICATION MATRIX:
βββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β LOGGING METHOD / CONFIG β METHOD SIGNATURE β TARGET SCOPE β PRIMARY OPERATIONAL PURPOSE β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββββ€
β Log Everything β .log().all() β Full Packet β Dumps all headers, URI & body β
β Log Body Only β .log().body() β Entity Body β Inspects serialized payload β
β Log Parameters Only β .log().parameters() β Params / Form β Logs query, path & form paramsβ
β Log Headers Only β .log().headers() β Transport Header β Inspects metadata & cookies β
β Log Target URI Only β .log().uri() β Target Address β Logs final resolved URL β
β Log Status Line Only β .log().status() β Status Envelope β Logs status code & reason lineβ
β Conditional Failure Log β .log().ifValidationFails() β On Error Only β Silent on pass; dumps on errorβ
β Blacklist Headers β LogConfig.blacklistHeaders() β Set<String> keys β Replaces tokens with [REDACTEDβ
β Blacklist Cookies β LogConfig.blacklistCookies() β Set<String> keys β Replaces cookies with [REDACTEβ
β Enable Pretty-Printing β LogConfig.enablePrettyPrint()β Boolean flag β Formats compact JSON into treeβ
β Redirect Stream β LogConfig.defaultStream() β PrintStream β Directs output to file sink β
β Global Log Config β RestAssured.config().logCon..β JVM Static Scope β Universal logging settings β
βββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββ΄ββββββββββββββββββββββββββββββββ€
β TOP 5 LOGGING & BLACKLISTING BEST PRACTICES: β
β 1. Always use log().ifValidationFails() in CI: Keep test build logs quiet while preserving debug data. β
β 2. Blacklist Authorization and API keys: Prevent secret credentials from leaking into test artifacts. β
β 3. Enable pretty-printing for JSON bodies: Transform minified payloads into clean indented trees. β
β 4. Never call log().body() on binary endpoints: Avoid crashing terminal buffers with raw file bytes. β
β 5. Redirect heavy test logs to file streams: Use custom PrintStream files to keep console logs clean. β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ