SELECTIVE LOGGING & BLACKLISTING: SECURITY, REDACTION & FAILURE TRIAGE

Architect production-grade wire diagnostics and security masking in REST Assured: Granular request/response logging (body, headers, params, uri), conditional failure logging with log().ifValidationFails(), header and cookie blacklisting via LogConfig, PrettyPrinting formatting, and custom PrintStream file sinks for CI/CD test runners.

πŸ”’ 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.

1. REST Assured Logging Pipeline & Redaction Architecture
The architectural breakdown of REST Assured's logging subsystem, showing how wire packets pass through LogConfig sanitizers, header/cookie blacklists, and selective formatters before printing to console or in-memory streams.
Logging Pipeline & Blacklisting Topology
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 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Architectural Standard: Test suites running in shared CI/CD environments must never log raw authentication tokens or unmasked customer credentials. Configuring LogConfig blacklisting ensures that sensitive data is stripped out before logs touch the console or build artifacts.
Real-Time Example 1: Granular Request & Response Logging Scopes
Isolating wire telemetry without dumping entire payloads. Demonstrates using granular scopesβ€”log().params(), log().headers(), log().body(), and log().status()β€”to observe specific HTTP message components.
Java (Selective Scope Logging: Params, Headers, Body & Status)
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.");
    }
}
Selective Log Console Output: Request params: Query params: academicTrack=ENTERPRISE_AUTOMATION page=1 limit=10 HTTP/1.1 200 OK Selective scoping keeps test logs focused on relevant parameters and status codes without megabytes of JSON body clutter.
Real-Time Example 2: Clean CI/CD Pipelines via log().ifValidationFails()
The industry standard for continuous integration pipelines. Configures log().ifValidationFails() on both request and response envelopes, ensuring tests remain completely silent during normal runs but dump full wire traces when assertions fail.
Java (Conditional Failure Logging for High-Speed CI Runs)
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.");
    }
}
CI Pipeline Diagnostic Output (Triggered on Failure): If an assertion fails, log().ifValidationFails() prints the complete wire transcript automatically: Request method: GET Request URI: https://staging-api.nikita-infotech.com/v1/students?track=ENTERPRISE_AUTOMATION Headers: Accept=*/* HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 Body: {"status": "SUCCESS", "total": 12, ...} java.lang.AssertionError: Expected status code <201> but was <200>.
Real-Time Example 3: Redacting Sensitive Headers via LogConfig.blacklistHeaders()
Preventing security credential leaks. Configures LogConfig.blacklistHeaders() to redact sensitive headers like Authorization, X-API-Key, and Proxy-Authorization from console and reporting output.
Java (Header Blacklisting & Masking Configuration)
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.");
    }
}
Sanitized Header Output: Headers: Authorization=[REDACTED] X-API-Key=[REDACTED] X-Public-Client=Automation-Worker The actual secrets were transmitted across the TLS socket to the server, but replaced with [REDACTED] in all logs.
Real-Time Example 4: Redacting Session Cookies via LogConfig.blacklistCookies()
Preventing session hijacking and credential theft in test logs. Uses LogConfig.blacklistCookies() to sanitize session cookies like JSESSIONID, SESSION_AFFINITY_ID, and remember_me tokens.
Java (Cookie Blacklisting & Session Redaction)
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.");
    }
}
Sanitized Cookie Output: Cookies: JSESSIONID=[REDACTED] SESSION_AFFINITY_ID=[REDACTED] ui_theme=dark_mode Non-sensitive configuration cookies (ui_theme) remain visible for triage while session tokens are masked.
Real-Time Example 5: JSON & XML Pretty-Printing Formatting
Improving readability for complex payloads. Configures enablePrettyPrinting(true) in LogConfig to automatically format compacted single-line JSON responses into indented, readable structures.
Java (Automated Pretty-Printing Format Configuration)
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.");
    }
}
Formatted Body Output: { "status": "SUCCESS", "timestamp": "2026-11-03T02:45:00Z", "data": { "id": "STU-88219", "fullName": "Nikita Sharma", "contactInfo": { "city": "Pune", "postalCode": "411015" } } } Transforms unformatted production JSON streams into human-readable nested trees.
Real-Time Example 6: Redirecting Logs to Files via Custom PrintStream
Isolating wire telemetry from the console. Uses 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.
Java (Redirecting Logging Output to File via PrintStream)
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!");
    }
}
File Output Audit: [*] Wire transcript written to file: /target/api-wire-audit.log Stdout console output: ZERO LINES. Complete request and response transcripts are preserved on disk for CI artifact archiving.
Real-Time Example 7: Global Logging Configuration via RequestSpecBuilder
Applying logging and blacklisting rules universally across an entire test framework. Bundles LogConfig sanitizers, header blacklists, and failure-only triggers into a shared RequestSpecBuilder template.
Java (Global Reusable Logging Specification 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.");
    }
}
Global Specification Telemetry: [*] Enterprise Logging & Blacklisting Specification initialized. Outbound request executed using enterpriseLoggingSpec: Target URI: https://staging-api.nikita-infotech.com/v1/students/STU-88219 Sensitive headers automatically masked; logs stay silent unless assertions fail.
Real-Time Example 8: Debugging Logging Pitfalls & Stream Leakage
Troubleshooting common logging mistakes: resolving java.io.IOException: Stream Closed on multi-read responses, managing memory usage during large binary downloads, and avoiding unclosed PrintStream file locks.
Java (Triage: Stream Closing & Binary Log Suppression)
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);
    }
}
Triage Output: Request URI: https://staging-api.nikita-infotech.com/v1/documents/DOC-88219/download HTTP/1.1 200 OK Content-Type: application/pdf | Content-Length: 482190 [*] Downloaded binary payload safely: 482190 bytes. By omitting .log().body(), the console remains clean and terminal emulators avoid binary lockups.
Real-Time Example 9: Logging & Blacklisting Specification Reference Matrix
A comprehensive reference summary pairing logging methods, configuration options, blacklisting directives, and operational best practices for REST Assured engineers.
Logging & Blacklisting Specification Reference Matrix
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.     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Engineering Best Practice: Strategic logging is essential for both test triaging and enterprise data security. By coupling log().ifValidationFails() with LogConfig header and cookie blacklists, you ensure that test runs stay quiet, credentials remain protected, and full diagnostic details are available whenever a test assertion fails.