diff --git a/includes/class-wc-payments.php b/includes/class-wc-payments.php index e9518324132..afae955e5e5 100644 --- a/includes/class-wc-payments.php +++ b/includes/class-wc-payments.php @@ -511,7 +511,7 @@ public static function init() { include_once __DIR__ . '/compat/multi-currency/class-wc-payments-currency-manager.php'; include_once __DIR__ . '/class-duplicates-detection-service.php'; - wcpay_get_container()->get( \WCPay\Internal\LoggerContext::class )->init(); + wcpay_get_container()->get( \WCPay\Internal\LoggerContext::class )->init_hooks(); self::$woopay_checkout_service = new Checkout_Service(); self::$woopay_checkout_service->init(); diff --git a/src/Internal/LoggerContext.php b/src/Internal/LoggerContext.php index f47176ff657..1f07033947e 100644 --- a/src/Internal/LoggerContext.php +++ b/src/Internal/LoggerContext.php @@ -57,17 +57,26 @@ class LoggerContext { private $entry_number = 0; /** - * Initialises the logger context. - * - * @return void + * LoggerContext constructor. */ - public function init() { + public function __construct() { $this->request_id = uniqid(); $this->entry_number = 0; - - $this->setup_hooks(); } + /** + * Adds hooks to filter and enhance log entries. + * + * @return void + */ + public function init_hooks() { + if ( $this->hooks_set ) { + return; + } + + add_filter( 'woocommerce_format_log_entry', [ $this, 'filter_log_entry' ], 10, 2 ); + $this->hooks_set = true; + } /** * Sets a context value. * @@ -134,20 +143,6 @@ function ( $line ) use ( $format_string ) { ); } - /** - * Adds hooks to filter and enhance log entries. - * - * @return void - */ - private function setup_hooks() { - if ( $this->hooks_set ) { - return; - } - - add_filter( 'woocommerce_format_log_entry', [ $this, 'filter_log_entry' ], 10, 2 ); - $this->hooks_set = true; - } - /** * Initialises the context. *