Class HttpLogger

java.lang.Object
io.fliqa.client.interledger.logging.HttpLogger

public class HttpLogger extends Object
Specialized HTTP request and response logger for debugging and monitoring API communications.

This logger is essential for debugging Interledger API interactions, especially when dealing with cryptographically signed requests and complex payment flows. It provides detailed logging of HTTP requests and responses at different log levels to support both development debugging and production monitoring.

Why This Logger is Needed

  • Payment Flow Debugging - Track Interledger payment process with detailed request/response logs
  • Signature Verification - Log signed request headers to verify Ed25519 signature generation
  • API Error Diagnosis - Capture full error responses for troubleshooting authentication and payment failures
  • Integration Testing - Monitor request/response patterns during integration with Interledger servers
  • Security Auditing - Log HTTP interactions for security analysis and compliance
  • Performance Monitoring - Track API response times and identify bottlenecks

Log Levels

  • DEBUG - Basic request/response information (method, URI, status code)
  • TRACE - Full request/response details including headers and body content

Security Considerations

Warning: TRACE level logging will log request and response bodies, which may contain sensitive information such as:

  • Access tokens and authorization headers
  • Payment amounts and wallet addresses
  • Cryptographic signatures and key identifiers

Use TRACE logging only in development and testing environments. In production, use DEBUG level to log essential information without exposing sensitive data.

Usage in Payment Flows

This logger is particularly valuable for debugging:

  • Grant request and response cycles
  • Quote generation and validation
  • Payment creation and completion status
  • Error responses from Interledger servers
  • Signature header verification

Request Body Handling

Unlike standard HTTP loggers, this implementation uses a custom subscriber to capture request bodies from the Java 11+ HTTP client's reactive streams API. This is necessary because request bodies are consumed as they're sent, making them unavailable for standard logging approaches.

Since:
1.0
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
    Custom subscriber for capturing HTTP request body content from reactive streams.
  • Constructor Summary

    Constructors
    Constructor
    Description
    HttpLogger(org.slf4j.Logger logger)
    Creates a new HTTP logger with the specified SLF4J logger.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Logs an HTTP request with appropriate detail level based on logger configuration.
    void
    Logs an HTTP response with appropriate detail level based on logger configuration.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HttpLogger

      public HttpLogger(org.slf4j.Logger logger)
      Creates a new HTTP logger with the specified SLF4J logger.
      Parameters:
      logger - SLF4J logger instance to use for output
      Throws:
      IllegalArgumentException - if logger is null
  • Method Details

    • logRequest

      public void logRequest(HttpRequest req)
      Logs an HTTP request with appropriate detail level based on logger configuration.

      Logging behavior:

      • DEBUG level: Logs method, URI, and basic request information
      • TRACE level: Logs complete request including headers and body

      For requests with bodies, this method uses a custom subscriber to capture the request body content as it's being sent, since the Java HTTP client consumes the body stream during transmission.

      Parameters:
      req - HTTP request to log
    • logResponse

      public void logResponse(HttpResponse<String> res)
      Logs an HTTP response with appropriate detail level based on logger configuration.

      Logging behavior:

      • DEBUG level: Logs status code, URI, and basic response information
      • TRACE level: Logs complete response including headers and body

      This is particularly useful for debugging API errors, monitoring payment status responses, and verifying server responses during the Interledger payment flow.

      Parameters:
      res - HTTP response to log