From f6efcb62c25ecb798c7a0f579e8ea0cc920a8b6e Mon Sep 17 00:00:00 2001 From: Bartek Jaskulski <bartek.jaskulski@wpdesk.net> Date: Tue, 17 May 2022 08:03:48 +0000 Subject: [PATCH] Bugfix/no handler --- CHANGELOG.md | 5 +++++ src/SimpleLoggerFactory.php | 21 +++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2685220..0be4d41 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 4e59eb8..169877c 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 ); -- GitLab