Made WC_Logger pluggable via wc_get_logger function.

Closes #11474
This commit is contained in:
Mike Jolley 2016-08-08 13:59:23 +01:00
parent 87443763d8
commit cfe28c9b25
10 changed files with 25 additions and 15 deletions

View File

@ -368,7 +368,7 @@ class WC_Admin_Status {
}
if ( ! empty( $_REQUEST[ 'handle' ] ) ) {
$logger = new WC_Logger();
$logger = wc_get_logger();
$logger->remove( $_REQUEST[ 'handle' ] );
}

View File

@ -36,7 +36,7 @@ class WC_Background_Updater extends WP_Background_Process {
*/
public function dispatch() {
$dispatched = parent::dispatch();
$logger = new WC_Logger();
$logger = wc_get_logger();
if ( is_wp_error( $dispatched ) ) {
$logger->add( 'wc_db_updates', sprintf( 'Unable to dispatch WooCommerce updater: %s', $dispatched->get_error_message() ) );
@ -97,7 +97,7 @@ class WC_Background_Updater extends WP_Background_Process {
define( 'WC_UPDATING', true );
}
$logger = new WC_Logger();
$logger = wc_get_logger();
include_once( dirname( __FILE__ ) . '/wc-update-functions.php' );
@ -119,7 +119,7 @@ class WC_Background_Updater extends WP_Background_Process {
* performed, or, call parent::complete().
*/
protected function complete() {
$logger = new WC_Logger();
$logger = wc_get_logger();
$logger->add( 'wc_db_updates', 'Data update complete' );
WC_Install::update_db_version();
parent::complete();

View File

@ -1168,12 +1168,8 @@ class WC_Geo_IP {
* @param string $message
*/
public static function log( $message ) {
if ( ! class_exists( 'WC_Logger' ) ) {
include_once( dirname( __FILE__ ) . '/class-wc-logger.php' );
}
if ( empty( self::$log ) ) {
self::$log = new WC_Logger();
self::$log = wc_get_logger();
}
self::$log->add( 'geoip', $message );
}

View File

@ -176,7 +176,7 @@ class WC_Geolocation {
* Update geoip database. Adapted from https://wordpress.org/plugins/geoip-detect/.
*/
public static function update_database() {
$logger = new WC_Logger();
$logger = wc_get_logger();
if ( ! is_callable( 'gzopen' ) ) {
$logger->add( 'geolocation', 'Server does not support gzopen' );

View File

@ -221,7 +221,7 @@ class WC_Install {
*/
private static function update() {
$current_db_version = get_option( 'woocommerce_db_version' );
$logger = new WC_Logger();
$logger = wc_get_logger();
$update_queued = false;
foreach ( self::$db_updates as $version => $update_callbacks ) {

View File

@ -411,7 +411,7 @@ class WC_Email extends WC_Settings_API {
$emogrifier = new Emogrifier( $content, $css );
$content = $emogrifier->emogrify();
} catch ( Exception $e ) {
$logger = new WC_Logger();
$logger = wc_get_logger();
$logger->add( 'emogrifier', $e->getMessage() );
}
}

View File

@ -79,7 +79,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
public static function log( $message ) {
if ( self::$log_enabled ) {
if ( empty( self::$log ) ) {
self::$log = new WC_Logger();
self::$log = wc_get_logger();
}
self::$log->add( 'paypal', $message );
}

View File

@ -1415,3 +1415,16 @@ function wc_get_rounding_precision() {
}
return $precision;
}
/**
* Returns a new instance of a WC Logger.
* Use woocommerce_logging_class filter to change the logging class.
* @return WC_Logger
*/
function wc_get_logger() {
if ( ! class_exists( 'WC_Logger' ) ) {
include_once( dirname( __FILE__ ) . '/class-wc-logger.php' );
}
$class = apply_filters( 'woocommerce_logging_class', 'WC_Logger' );
return new $class;
}

View File

@ -167,6 +167,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* On multisite, when a user logs into a store with an account on a site, but not the current site, rather than error, add the user to the current site as a customer.
* Show variable weights/dimensions even when parent values are not set.
* Automatically sort tax rates rather than allow clunky manual sorting.
* Made WC_Logger pluggable via wc_get_logger function.
[See changelog for all versions](https://raw.githubusercontent.com/woothemes/woocommerce/master/CHANGELOG.txt).

View File

@ -16,7 +16,7 @@ class WC_Tests_Log extends WC_Unit_Test_Case {
* @since 2.4
*/
public function test_add() {
$log = new WC_Logger();
$log = wc_get_logger();
$log->add( 'unit-tests', 'this is a message' );
@ -30,7 +30,7 @@ class WC_Tests_Log extends WC_Unit_Test_Case {
* @since 2.4
*/
public function test_clear() {
$log = new WC_Logger();
$log = wc_get_logger();
$log->add( 'unit-tests', 'this is a message' );
$log->clear( 'unit-tests' );