[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/includes/ -> functions-debug.php (source)

   1  <?php
   2  /*
   3   * Functions relative to debugging
   4   */
   5  
   6  /**
   7   * Add a message to the debug log
   8   *
   9   * When in debug mode ( YOURLS_DEBUG == true ) the debug log is echoed in yourls_html_footer()
  10   * Log messages are appended to $ydb->debug_log array, which is instanciated within class Database\YDB
  11   *
  12   * @since 1.7
  13   * @param string $msg Message to add to the debug log
  14   * @return string The message itself
  15   */
  16  function yourls_debug_log( $msg ) {
  17      yourls_do_action( 'debug_log', $msg );
  18      // Get the DB object ($ydb), get its profiler (\Aura\Sql\Profiler\Profiler), its logger (\Aura\Sql\Profiler\MemoryLogger) and
  19      // pass it a unused argument (loglevel) and the message
  20      // Check if function exists to allow usage of the function in very early stages
  21      if(function_exists('yourls_debug_log')) {
  22          yourls_get_db()->getProfiler()->getLogger()->log( 'debug', $msg);
  23      }
  24      return $msg;
  25  }
  26  
  27  /**
  28   * Get the debug log
  29   *
  30   * @since  1.7.3
  31   * @return array
  32   */
  33  function yourls_get_debug_log() {
  34      return yourls_get_db()->getProfiler()->getLogger()->getMessages();
  35  }
  36  
  37  /**
  38   * Get number of SQL queries performed
  39   *
  40   * @return int
  41   */
  42  function yourls_get_num_queries() {
  43      return yourls_apply_filter( 'get_num_queries', yourls_get_db()->get_num_queries() );
  44  }
  45  
  46  /**
  47   * Debug mode set
  48   *
  49   * @since 1.7.3
  50   * @param bool $bool Debug on or off
  51   * @return void
  52   */
  53  function yourls_debug_mode( $bool ) {
  54      // log queries if true
  55      yourls_get_db()->getProfiler()->setActive( (bool)$bool );
  56  
  57      // report notices if true
  58      $level = $bool ? -1 : ( E_ERROR | E_PARSE );
  59      error_reporting( $level );
  60  }
  61  
  62  /**
  63   * Return YOURLS debug mode
  64   *
  65   * @since 1.7.7
  66   * @return bool
  67   */
  68  function yourls_get_debug_mode() {
  69      return defined( 'YOURLS_DEBUG' ) && YOURLS_DEBUG;
  70  }


Generated: Sat Feb 22 05:10:06 2025 Cross-referenced by PHPXref 0.7.1