GravityView  2.17
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 
4 
5 /**
6  * @TODO (Foundation) Deprecate in future versions or write a wrapper for Foundation Logger so that all methods are accessible through gravity()->plugin->log() or something.
7  */
8 final class GravityView_Logging {
9  private static $_logger;
10 
11  function __construct() {
12  // GravityKitFoundation may not yet be available at this point, so we use the included version of Foundation and then swap with the latest version once it's available.
13  self::$_logger = LoggerFramework::get_instance( 'gravityview', 'GravityView' );
14 
15  add_action( 'gk/foundation/initialized', function ( $foundation ) {
16  self::$_logger = $foundation::logger( 'gravityview', 'GravityView' );
17  } );
18 
19  // We're keeping `gravityview_log_*` actions for backward compatibility, but they are unnecessary as any plugin can simply use GravityKitFoundation::logger() functionality.
20  add_action( 'gravityview_log_error', array( $this, 'log_error'), 10, 2 );
21 
22  add_action( 'gravityview_log_debug', array( $this, 'log_debug'), 10, 2 );
23  }
24 
25  /**
26  * Get the name of the function to print messages for debugging
27  *
28  * This is necessary because `ob_start()` doesn't allow `print_r()` inside it.
29  *
30  * @return string "print_r" or "var_export"
31  */
32  static function get_print_function() {
33  if( ob_get_level() > 0 ) {
34  $function = 'var_export';
35  } else {
36  $function = 'print_r';
37  }
38 
39  return $function;
40  }
41 
42  static function log_debug( $message = '', $data = null ) {
43  $function = self::get_print_function();
44 
45  $message = $function( $message, true ) . $function($data, true);
46 
47  self::$_logger->debug( $message );
48  }
49 
50  static function log_error( $message = '', $data = null ) {
51  $function = self::get_print_function();
52 
53  $error = array(
54  'message' => $message,
55  'data' => $data,
56  'backtrace' => function_exists( 'wp_debug_backtrace_summary' ) ? wp_debug_backtrace_summary( null, 3 ) : '',
57  );
58 
59  $message = $function ( $message, true ) . $function ( $error, true);
60 
61  self::$_logger->error( $message );
62  }
63 }
64 
static get_print_function()
Get the name of the function to print messages for debugging.
new GravityView_Logging
static log_error( $message='', $data=null)
static log_debug( $message='', $data=null)
(Foundation) Deprecate in future versions or write a wrapper for Foundation Logger so that all method...