Skip to content
Snippets Groups Projects
Commit f66adf01 authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

Merge branch 'feature/wc-logger' into 'master'

bugfix(factory): wc logger

See merge request !24
parents 53d172c0 91e6800a
No related branches found
No related tags found
1 merge request!24bugfix(factory): wc logger
Pipeline #125779 passed with warnings
## [1.10.1] - 2022-10-01
### Fixed
- WC logger initialisation
## [1.10.0] - 2022-08-16
### Added
- en_CA, en_GB translators
......
......@@ -15,4 +15,15 @@ final class Settings {
/** @var bool */
public $use_wp_log = true;
/**
* @param string $level
* @param bool $use_wc_log
* @param bool $use_wp_log
*/
public function __construct( string $level = LogLevel::DEBUG, bool $use_wc_log = true, bool $use_wp_log = true ) {
$this->level = $level;
$this->use_wc_log = $use_wc_log;
$this->use_wp_log = $use_wp_log;
}
}
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment