Jetpack_Sitemap_Logger

Handles logging errors and debug messages for sitemap generator.

Defined (1)

The class is defined in the following location(s).

/modules/sitemaps/sitemap-logger.php  
  1. class Jetpack_Sitemap_Logger { 
  2. /** 
  3. * A unique-ish string for each logger, enabling us to grep 
  4. * for the messages written by an individual generation phase. 
  5. * @access private 
  6. * @since 4.8.0 
  7. * @var string $key The key string. 
  8. */ 
  9. private $key; 
  10.  
  11. /** 
  12. * The birth time of this object in microseconds. 
  13. * @access private 
  14. * @since 4.8.0 
  15. * @var int $starttime The birth time. 
  16. */ 
  17. private $starttime; 
  18.  
  19. /** 
  20. * Initializes a new logger object. 
  21. * @access public 
  22. * @since 4.8.0 
  23. * @param string $message An optional message string to be written to the debug log on initialization. 
  24. */ 
  25. public function __construct( $message = null ) { 
  26. $this->key = wp_generate_password( 5, false ); 
  27. $this->starttime = microtime( true ); 
  28. if ( ! is_null( $message ) ) { 
  29. $this->report( $message ); 
  30. return; 
  31.  
  32. /** 
  33. * Writes a string to the debug log, including the logger's ID string. 
  34. * @access public 
  35. * @since 4.8.0 
  36. * @param string $message The string to be written to the log. 
  37. */ 
  38. public function report( $message ) { 
  39. if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { 
  40. error_log( 'jp-sitemap-' . $this->key . ': ' . $message ); 
  41. return; 
  42.  
  43. /** 
  44. * Writes the elapsed lifetime of the logger to the debug log, with an optional message. 
  45. * @access public 
  46. * @since 4.8.0 
  47. * @param string $message The optional message string. Default is the empty string. 
  48. */ 
  49. public function time( $message = '' ) { 
  50. $time = round( microtime( true ) - $this->starttime, 3 ); 
  51. $this->report( $message . ' ' . $time . ' seconds elapsed.' ); 
  52. return;