GravityView  1.19.4
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-logging.php
Go to the documentation of this file.
1 <?php
2 
3 final class GravityView_Logging {
4 
5  private static $errors = array();
6  private static $notices = array();
7 
8  function __construct() {
9 
10  add_action( 'gravityview_log_error', array( $this, 'log_error'), 10, 2 );
11 
12  add_action( 'gravityview_log_debug', array( $this, 'log_debug'), 10, 2 );
13 
14  // Enable debug with Gravity Forms Logging Add-on
15  add_filter( 'gform_logging_supported', array( $this, 'enable_gform_logging' ) );
16 
17  // Load Debug Bar integration
18  add_filter( 'debug_bar_panels', array( $this, 'add_debug_bar' ) );
19 
20  }
21 
22  /**
23  * Add integration with the Debug Bar plugin. It's awesome.
24  *
25  * @see http://wordpress.org/plugins/debug-bar/
26  */
27  public function add_debug_bar( $panels ) {
28 
29  if ( ! class_exists( 'Debug_Bar_Panel' ) ) {
30  return;
31  }
32 
33  if ( ! class_exists( 'GravityView_Debug_Bar' ) ) {
34  include_once( GRAVITYVIEW_DIR . 'includes/class-debug-bar.php' );
35  }
36 
37  $panels[] = new GravityView_Debug_Bar;
38 
39  return $panels;
40  }
41 
42  /**
43  * Enables debug with Gravity Forms logging add-on
44  * @param array $supported_plugins List of plugins
45  */
46  public function enable_gform_logging( $supported_plugins ) {
47  $supported_plugins['gravityview'] = 'GravityView';
48  return $supported_plugins;
49  }
50 
51  /**
52  * @static
53  * @return array Array of notices (with `message`, `data`, and `backtrace` keys), if any
54  */
55  public static function get_notices() {
56  return self::$notices;
57  }
58 
59  /**
60  * @static
61  * @return array Array of errors (with `message`, `data`, and `backtrace` keys), if any
62  */
63  public static function get_errors() {
64  return self::$errors;
65  }
66 
67  /**
68  * Get the name of the function to print messages for debugging
69  *
70  * This is necessary because `ob_start()` doesn't allow `print_r()` inside it.
71  *
72  * @return string "print_r" or "var_export"
73  */
74  static function get_print_function() {
75  if( ob_get_level() > 0 ) {
76  $function = 'var_export';
77  } else {
78  $function = 'print_r';
79  }
80 
81  return $function;
82  }
83 
84  static function log_debug( $message = '', $data = null ) {
85 
86  $function = self::get_print_function();
87 
88  $notice = array(
89  'message' => $function( $message, true ),
90  'data' => $data,
91  'backtrace' => function_exists('wp_debug_backtrace_summary') ? wp_debug_backtrace_summary( null, 3 ) : '',
92  );
93 
94  if( !in_array( $notice, self::$notices ) ) {
95  self::$notices[] = $notice;
96  }
97 
98  if ( class_exists("GFLogging") ) {
99  GFLogging::include_logger();
100  GFLogging::log_message( 'gravityview', $function( $message, true ) . $function($data, true), KLogger::DEBUG );
101  }
102  }
103 
104  static function log_error( $message = '', $data = null ) {
105 
106  $function = self::get_print_function();
107 
108  $error = array(
109  'message' => $message,
110  'data' => $data,
111  'backtrace' => function_exists('wp_debug_backtrace_summary') ? wp_debug_backtrace_summary( null, 3 ) : '',
112  );
113 
114  if( !in_array( $error, self::$errors ) ) {
115  self::$errors[] = $error;
116  }
117 
118  if ( class_exists("GFLogging") ) {
119  GFLogging::include_logger();
120  GFLogging::log_message( 'gravityview', $function ( $message, true ) . $function ($data, true), KLogger::ERROR );
121  }
122  }
123 
124 }
125 
const GRAVITYVIEW_DIR
"GRAVITYVIEW_DIR" "./" The absolute path to the plugin directory
Definition: gravityview.php:35
static get_print_function()
Get the name of the function to print messages for debugging.
add_debug_bar($panels)
Add integration with the Debug Bar plugin.
static log_error($message= '', $data=null)
new GravityView_Logging
enable_gform_logging($supported_plugins)
Enables debug with Gravity Forms logging add-on.
static log_debug($message= '', $data=null)