[ 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 at startup or yourls_debug_mode() set to true later on), the debug log is
  10   * echoed in yourls_html_footer().
  11   * Log messages are appended to $ydb->debug_log array, which is instantiated within class Database\YDB
  12   *
  13   * @since 1.7
  14   * @param string $msg Message to add to the debug log
  15   * @return string The message itself
  16   */
  17  function yourls_debug_log(string $msg): string {
  18      if (yourls_get_debug_mode()) {
  19          yourls_do_action('debug_log', $msg);
  20          yourls_get_db('read-debug_log')->getProfiler()->getLogger()->log('debug', $msg);
  21      }
  22      return $msg;
  23  }
  24  
  25  /**
  26   * Get the debug log
  27   *
  28   * @since  1.7.3
  29   * @return array
  30   */
  31  function yourls_get_debug_log(): array {
  32      return yourls_get_db('read-get_debug_log')->getProfiler()->getLogger()->getMessages();
  33  }
  34  
  35  /**
  36   * Get number of SQL queries performed
  37   *
  38   * @return int
  39   */
  40  function yourls_get_num_queries(): int {
  41      return yourls_apply_filter( 'get_num_queries', yourls_get_db('read-get_num_queries')->get_num_queries() );
  42  }
  43  
  44  /**
  45   * Debug mode set
  46   *
  47   * @since 1.7.3
  48   * @param bool $bool Debug on or off
  49   * @return void
  50   */
  51  function yourls_debug_mode(bool $bool): void {
  52      // log queries if true
  53      yourls_get_db('read-debug_mode')->getProfiler()->setActive( (bool)$bool );
  54  
  55      // report notices if true
  56      $level = $bool ? -1 : ( E_ERROR | E_PARSE );
  57      error_reporting( $level );
  58  }
  59  
  60  /**
  61   * Return YOURLS debug mode
  62   *
  63   * @since 1.7.7
  64   * @return bool
  65   */
  66  function yourls_get_debug_mode(): bool {
  67      return yourls_get_db('read-debug_mode')->getProfiler()->isActive();
  68  }


Generated: Sat Jun 13 05:10:47 2026 Cross-referenced by PHPXref 0.7.1