mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
🧑💻 Log the request path to give more context
This commit is contained in:
parent
e9450f0100
commit
6ed6b8c3ba
1 changed files with 25 additions and 0 deletions
|
@ -36,6 +36,14 @@ class WooCommerceLogger implements LoggerInterface {
|
|||
*/
|
||||
private string $source;
|
||||
|
||||
/**
|
||||
* Details that are output before the first real log message, to help
|
||||
* identify the request.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $request_info;
|
||||
|
||||
/**
|
||||
* A random prefix which is visible in every log message, to better
|
||||
* understand which messages belong to the same request.
|
||||
|
@ -54,6 +62,14 @@ class WooCommerceLogger implements LoggerInterface {
|
|||
$this->wc_logger = $wc_logger;
|
||||
$this->source = $source;
|
||||
$this->prefix = sprintf( '#%s - ', wp_rand( 1000, 9999 ) );
|
||||
|
||||
// phpcs:disable -- Intentionally not sanitized, for logging purposes.
|
||||
$method = wp_unslash( $_SERVER['REQUEST_METHOD'] ?? 'CLI' );
|
||||
$request_uri = wp_unslash( $_SERVER['REQUEST_URI'] ?? '-' );
|
||||
// phpcs:enable
|
||||
|
||||
$request_path = wp_parse_url( $request_uri, PHP_URL_PATH );
|
||||
$this->request_info = "$method $request_path";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,6 +84,15 @@ class WooCommerceLogger implements LoggerInterface {
|
|||
$context['source'] = $this->source;
|
||||
}
|
||||
|
||||
if ( $this->request_info ) {
|
||||
$this->wc_logger->log(
|
||||
'debug',
|
||||
"{$this->prefix}[New Request] $this->request_info",
|
||||
array( 'source' => $context['source'] )
|
||||
);
|
||||
$this->request_info = '';
|
||||
}
|
||||
|
||||
$this->wc_logger->log( $level, "{$this->prefix}$message", $context );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue