wc_get_logger

Get a shared logger instance.

Description

(WC_Logger) wc_get_logger(); 

Use the woocommerce_logging_class filter to change the logging class. You may provide one of the following: In either case, the class or instance *must* implement WC_Logger_Interface.

Returns (WC_Logger)


Usage

  1. if ( !function_exists( 'wc_get_logger' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-core-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wc_get_logger(); 
  7.  

Defined (1)

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

/includes/wc-core-functions.php  
  1. function wc_get_logger() { 
  2. static $logger = null; 
  3. if ( null === $logger ) { 
  4. $class = apply_filters( 'woocommerce_logging_class', 'WC_Logger' ); 
  5. $implements = class_implements( $class ); 
  6. if ( is_array( $implements ) && in_array( 'WC_Logger_Interface', $implements ) ) { 
  7. if ( is_object( $class ) ) { 
  8. $logger = $class; 
  9. } else { 
  10. $logger = new $class; 
  11. } else { 
  12. __FUNCTION__,  
  13. sprintf( 
  14. __( 'The class <code>%s</code> provided by woocommerce_logging_class filter must implement <code>WC_Logger_Interface</code>.', woocommerce ),  
  15. esc_html( is_object( $class ) ? get_class( $class ) : $class ) 
  16. ),  
  17. '3.0' 
  18. ); 
  19. $logger = new WC_Logger(); 
  20. return $logger;