diff --git a/CHANGELOG.md b/CHANGELOG.md index 26852208fac276123e831674b57a61bf56bd2154..0be4d4103a6d1bc251fb74f675c641ca0d5f186e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [Unreleased] +### Fixed +- Fixed no handler actually assigned when using combination of + NullHandler and actual one + ## [1.7.1] - 2022-04-15 ### Fixed - Fixed the getLogger method from SimpleLoggerFactory diff --git a/src/SimpleLoggerFactory.php b/src/SimpleLoggerFactory.php index 4e59eb8d329881d4c11f66ffb858eee29ebaba75..169877cbd1c2c1bdbf7bcd2ca19b53c7b10052be 100644 --- a/src/SimpleLoggerFactory.php +++ b/src/SimpleLoggerFactory.php @@ -32,26 +32,23 @@ final class SimpleLoggerFactory implements LoggerFactory { $logger = new Logger( $this->channel ); - $wc_handler = $this->get_wc_handler(); - if ( $this->options->use_wc_log ) { - $logger->pushHandler( $wc_handler ); + if ( $this->options->use_wc_log && \function_exists( 'wc_get_logger' ) ) { + $logger->pushHandler( + new WooCommerceHandler( + \wc_get_logger(), + $this->options->levels + ) + ); } - if ( $this->options->use_wp_log || $wc_handler instanceof NullHandler ) { + // Adding WooCommerce logger may have failed, if so add WP by default. + if ( $this->options->use_wp_log || empty( $logger->getHandlers() ) ) { $logger->pushHandler( $this->get_wp_handler() ); } return $this->logger = $logger; } - private function get_wc_handler(): HandlerInterface { - if ( function_exists( 'wc_get_logger' ) ) { - return new WooCommerceHandler( wc_get_logger(), $this->options->level ); - } - - return new NullHandler(); - } - private function get_wp_handler(): HandlerInterface { if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) { return new ErrorLogHandler( ErrorLogHandler::OPERATING_SYSTEM, $this->options->level );