Merge pull request #25 from woocommerce/fix/8199
Add logger for tracks events
This commit is contained in:
commit
144ab092dd
|
@ -35,3 +35,4 @@ require( 'options/rest-api.php' );
|
||||||
require( 'tools/delete-all-products.php');
|
require( 'tools/delete-all-products.php');
|
||||||
require( 'tools/disable-wc-email.php' );
|
require( 'tools/disable-wc-email.php' );
|
||||||
require( 'tools/trigger-update-callbacks.php' );
|
require( 'tools/trigger-update-callbacks.php' );
|
||||||
|
require( 'tracks/tracks-debug-log.php' );
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class for logging tracked events.
|
||||||
|
*/
|
||||||
|
class TracksDebugLog {
|
||||||
|
/**
|
||||||
|
* Logger class to use.
|
||||||
|
*
|
||||||
|
* @var WC_Logger_Interface|null
|
||||||
|
*/
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger source.
|
||||||
|
*
|
||||||
|
* @var string logger source.
|
||||||
|
*/
|
||||||
|
private $source = 'tracks';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize hooks.
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
add_filter( 'woocommerce_tracks_event_properties', array( $this, 'log_event' ), 10, 2 );
|
||||||
|
$logger = wc_get_logger();
|
||||||
|
$this->logger = $logger;
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log the event.
|
||||||
|
*
|
||||||
|
* @param array $properties Event properties.
|
||||||
|
* @param string $event_name Event name.
|
||||||
|
*/
|
||||||
|
public function log_event( $properties, $event_name ) {
|
||||||
|
$this->logger->debug(
|
||||||
|
$event_name,
|
||||||
|
array( 'source' => $this->source )
|
||||||
|
);
|
||||||
|
foreach ( $properties as $key => $property ) {
|
||||||
|
$this->logger->debug(
|
||||||
|
" - {$key}: {$property}",
|
||||||
|
array( 'source' => $this->source )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $properties;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new TracksDebugLog();
|
Loading…
Reference in New Issue