/app/helper/class-ms-helper-debug.php

  1. <?php 
  2. if ( ! defined( 'WP_DEBUG' ) ) { 
  3. define( 'WP_DEBUG', false ); 
  4.  
  5. if ( ! defined( 'WDEV_DEBUG' ) ) { 
  6. define( 'WDEV_DEBUG', false ); 
  7.  
  8. /** 
  9. * This Helper creates utility functions for debugging. 
  10. * 
  11. * @since 1.0.0 
  12. * @package Membership2 
  13. * @subpackage Controller 
  14. */ 
  15. class MS_Helper_Debug extends MS_Helper { 
  16. /** 
  17. * Logs errors to WordPress debug log. 
  18. * 
  19. * The following constants ned to be set in wp-config.php 
  20. * or elsewhere where turning on and off debugging makes sense. 
  21. * 
  22. * // Essential 
  23. * define('WP_DEBUG', true); 
  24. * // Enables logging to /wp-content/debug.log 
  25. * define('WP_DEBUG_LOG', true); 
  26. * // Force debug messages in WordPress to be turned off (using logs instead) 
  27. * define('WP_DEBUG_DISPLAY', false); 
  28. * 
  29. * @since 1.0.0 
  30. * @param mixed $message Array, object or text to output to log. 
  31. */ 
  32. public static function log( $message, $echo_file = false ) { 
  33. if ( ! WP_DEBUG && ! WDEV_DEBUG ) { return; } 
  34.  
  35. if ( defined( 'DEBUG_BACKTRACE_IGNORE_ARGS' ) ) { 
  36. $trace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); 
  37. } else { 
  38. $trace = debug_backtrace(); 
  39.  
  40. $exception = new Exception(); 
  41. $debug = array_shift( $trace ); 
  42. $caller = array_shift( $trace ); 
  43. $exception = $exception->getTrace(); 
  44. $callee = array_shift( $exception ); 
  45.  
  46. $msg = isset( $caller['class'] ) ? $caller['class'] . '[' . $callee['line'] . ']: ' : ''; 
  47.  
  48. if ( is_array( $message ) || is_object( $message ) ) { 
  49. $msg .= print_r( $message, true ); 
  50. } else { 
  51. $msg .= $message; 
  52.  
  53. if ( $echo_file ) { 
  54. $msg .= "\nIn " . $callee['file'] . ' on line ' . $callee['line']; 
  55.  
  56. error_log( $msg ); 
  57.  
  58. public static function debug_trace( $return = false ) { 
  59. if ( ! WP_DEBUG && ! WDEV_DEBUG ) { return; } 
  60.  
  61. $traces = debug_backtrace(); 
  62. $fields = array( 
  63. 'file',  
  64. 'line',  
  65. 'function',  
  66. 'class',  
  67. ); 
  68. $log = array( '---------------------------- Trace start ----------------------------' ); 
  69.  
  70. foreach ( $traces as $i => $trace ) { 
  71. $line = array(); 
  72. foreach ( $fields as $field ) { 
  73. if ( ! empty( $trace[ $field ] ) ) { 
  74. $line[] = "$field: {$trace[ $field ]}"; 
  75. $log[] = " [$i]". implode( '; ', $line ); 
  76.  
  77. if ( $return ) { 
  78. return implode( "\n", $log ); 
  79. } else { 
  80. error_log( implode( "\n", $log ) ); 
  81.  
  82.  
  83. MS_Helper_Debug::log( '**************************** REQUEST START ****************************' ); 
  84. MS_Helper_Debug::log( '***** URL: ' . lib3()->net->current_url() ); 
.