Skip to content
Snippets Groups Projects
Verified Commit 78dc5eeb authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

fix: add option for setting channel in WooCommerce logger

parent dabf6516
No related branches found
No related tags found
1 merge request!19Bugfix/default channel
Pipeline #7592 passed with stages
in 3 minutes and 15 seconds
......@@ -46,7 +46,7 @@ final class SimpleLoggerFactory implements LoggerFactory {
private function get_wc_handler(): HandlerInterface {
if ( function_exists( 'wc_get_logger' ) ) {
return new WooCommerceHandler( wc_get_logger(), $this->options->level );
return new WooCommerceHandler( wc_get_logger(), $this->channel );
}
return new NullHandler();
......
......@@ -9,36 +9,43 @@ use Monolog\Logger;
* Class WooCommerceFactory
*/
class WooCommerceHandler extends AbstractProcessingHandler {
const DEFAULT_WC_SOURCE = 'wpdesk-logger';
const DEFAULT_WC_SOURCE = 'wpdesk-logger';
/** @var \WC_Logger_Interface */
private $wc_logger;
/**
* Writes the record down to the log of the implementing handler
*
* @param array $record
* @return void
*/
protected function write(array $record)
{
$context = array_merge([
'source' => self::DEFAULT_WC_SOURCE
], $record['extra'], $record['context']);
$this->wc_logger->log($this->convertMonologLevelToWC($record['level']), $record['message'], $context);
/** @var string */
private $channel;
/**
* Writes the record down to the log of the implementing handler
*
* @param array $record
* @return void
*/
protected function write( array $record ) {
$context = array_merge(
[
'source' => $this->channel;,
],
$record['extra'],
$record['context']
);
$this->wc_logger->log( $this->convertMonologLevelToWC( $record['level'] ), $record['message'], $context );
}
/**
* @param int $level
* @return string
*/
private function convertMonologLevelToWC($level) {
return Logger::getLevelName($level);
}
/**
* @param int $level
* @return string
*/
private function convertMonologLevelToWC( $level ) {
return Logger::getLevelName( $level );
}
public function __construct(\WC_Logger_Interface $originalWcLogger) {
public function __construct( \WC_Logger_Interface $originalWcLogger, string $channel = self::DEFAULT_WC_SOURCE ) {
parent::__construct();
$this->wc_logger = $originalWcLogger;
$this->channel = $channel;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment