Skip to content
Snippets Groups Projects

bugfix(factory): wc logger

Merged Grzegorz Rola requested to merge feature/wc-logger into master
1 file
+ 1
1
Compare changes
  • Side-by-side
  • Inline
+ 26
12
@@ -30,23 +30,37 @@ final class SimpleLoggerFactory implements LoggerFactory {
return $this->logger;
}
$logger = new Logger( $this->channel );
$this->logger = new Logger( $this->channel );
if ( $this->options->use_wc_log && \function_exists( 'wc_get_logger' ) ) {
$logger->pushHandler(
new WooCommerceHandler(
\wc_get_logger(),
$this->channel
)
);
if ( $this->options->use_wc_log ) {
if ( \function_exists( 'wc_get_logger' ) ) {
$this->create_wc_handler();
} else {
\add_action( 'woocommerce_init', [ $this, 'create_wc_handler' ] );
}
}
// 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() );
if ( $this->options->use_wp_log || empty( $this->logger->getHandlers() ) ) {
$this->logger->pushHandler( $this->get_wp_handler() );
}
return $this->logger = $logger;
return $this->logger;
}
/**
* @internal
*/
public function create_wc_handler() {
while ( ! $this->options->use_wp_log && ! empty( $this->logger->getHandlers() ) ) {
$this->logger->popHandler();
}
$this->logger->pushHandler(
new WooCommerceHandler(
\wc_get_logger(),
$this->channel
)
);
}
private function get_wp_handler(): HandlerInterface {
Loading