How to log HTTP requests sent by ODataQueryBuilder API / VDM API?

Viewed 368

Using latest version of Java SAP Cloud SDK

We have some code which uses ODataQueryBuilder API and VDM API as well. We want to log the HTTP requests that are being sent by these API's. We want to log whole of the HTTP request - headers, body everything. Please note that our application is running on SAP Cloud Platform's Cloud Foundry PAAS offering and using cf set-logging-level doesn't seem to work.

2 Answers

I've been using this Java arg when debugging my requests, but I've been doing it locally.

-Dorg.slf4j.simpleLogger.log.org.apache.http.wire=debug

If you can pass it withing CF environment I think you should start seeing all the payloads. I'll research a bit more to provide a better guidance if this won't work for you.

For applications deployed on SCP CF, there are different setups for which recommend other logging practices. The goal is to configure individual log levels for specific packages of your application and third-party dependencies, e.g. SAP Cloud SDK or SAP Service SDK or Apache HTTP components.

TomEE based application:

  • Edit the manifest.yml to include the following env entry for environment variable:
    SET_LOGGING_LEVEL: '{ROOT: INFO, com.sap.cloud.sdk: INFO, org.apache.http.wire: DEBUG}'
    
    Feel free to customize.

Spring Boot based application:

  • We expect the logback framework.
  • Edit/Create the file: application/src/main/resources/logback-spring.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <springProfile name="!cloud">
            <include resource="org/springframework/boot/logging/logback/base.xml"/>
            <root level="INFO"/>
            <logger name="org.springframework.web" level="INFO"/>
        </springProfile>
    
        <springProfile name="cloud">
            <appender name="STDOUT-JSON" class="ch.qos.logback.core.ConsoleAppender">
                <encoder class="com.sap.hcp.cf.logback.encoder.JsonEncoder"/>
            </appender>
            <logger name="org.springframework.web" level="INFO"/>
            <logger name="com.sap.cloud.sdk" level="INFO"/>
            <logger name="org.apache.http.wire" level="DEBUG"/>
            <root level="INFO">
                <appender-ref ref="STDOUT-JSON"/>
            </root>
        </springProfile>
    </configuration>
    

    Feel free to customize.

  • Notice the different profile settings. Make sure the cloud profile is active for deployed applications. Edit the manifest.yml to include the following env entry for environment variable:
    SPRING_PROFILES_ACTIVE: 'cloud'
    
Related