woocommerce/api/tracks/tracks-debug-log.php

54 lines
974 B
PHP
Raw Normal View History

2022-01-27 16:34:34 +00:00
<?php
/**
* A class for logging tracked events.
*/
class TracksDebugLog {
2022-01-27 16:40:14 +00:00
/**
2022-01-27 16:34:34 +00:00
* Logger class to use.
*
* @var WC_Logger_Interface|null
*/
private $logger;
2022-01-27 16:40:14 +00:00
/**
2022-01-27 16:34:34 +00:00
* Logger source.
*
* @var string logger source.
*/
private $source = 'tracks';
2022-01-27 16:40:14 +00:00
/**
* Initialize hooks.
*/
public function __construct() {
add_filter( 'woocommerce_tracks_event_properties', array( $this, 'log_event' ), 10, 2 );
$logger = wc_get_logger();
2022-01-27 16:34:34 +00:00
$this->logger = $logger;
$this->logger = $logger;
2022-01-27 16:40:14 +00:00
}
2022-01-27 16:34:34 +00:00
2022-01-27 16:40:14 +00:00
/**
* 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 ) {
2022-01-27 16:34:34 +00:00
$this->logger->debug(
" - {$key}: {$property}",
array( 'source' => $this->source )
);
}
2022-01-27 16:40:14 +00:00
return $properties;
}
2022-01-27 16:34:34 +00:00
}
2022-01-27 16:40:51 +00:00
new TracksDebugLog();