Troubleshooting: Log Requests to & Responses from QPilot API to Wordpress Debug Log

In this example a developer logs requests to and responses from the QPilot API in order to troubleshoot a plugin suspecting of changing product data sent to QPilot. Reviewing their Wordpress debug.log file they will be able to trace where products were changed by looking at the request method, endpoints, and payload.

Example

Step 1

In the example below a dev uses a simple debug statement to log the details of Requests to & Responses from the QPilot API.

  /**
  * Simple Debug Code
  */

  if ( !function_exists( 'xx_debug' ) ) {
	function xx_debug ($variable, $log = false ) {
  
     if ( !$log ){
	  echo '<pre>';
	  print_r($variable);
	  echo '</pre>'; 
      } else { 
           error_log(print_r($variable, true)); } 
    } 
}

Step 2

Next, the dev creates 2 functions to log both the Request ('xx_log_action_calls') to and Response ('xx_log_action_call_response') from the QPilot API to their Wordpress debug.log file

function xx_log_action_calls( $args ){

	xx_debug( '==============================================[ ' . $args['method'] . ' START CALL ]==============================================', true );
	xx_debug( $args, true );
	xx_debug( '==============================================[ END CALL ' . $args['method'] . ' ]==============================================', true );
  
  }
add_action('qpilot_remote_request', 'xx_log_action_calls', 10, 1 );
  
  
  function xx_log_action_call_response( $args ){
  
	xx_debug( '==============================================[ ' . $args['method'] . ' CALL RESPONSE ]==============================================', true );
	xx_debug( $args['response'], true );
	xx_debug( '==============================================[ END CALL RESPONSE ' . $args['method'] . ' ]==============================================', true );
  
  }
  
add_action('qpilot_remote_request_response', 'xx_log_action_call_response', 10, 1 );

Still need help? Contact Us Contact Us