Logging: Ensure filtered log messages don't persist across multiple log handlers (#48336)

Log messages can be modified via the `woocommerce_logger_log_message`
filter hook on a per-handler basis, but if the message is modified for
the first handler, the subsequent handlers were receiving the modified
message instead of the original. This simply ensures each handler
receives the original message instead.

Fixes #47126
This commit is contained in:
Corey McKrill 2024-06-11 10:33:02 -07:00 committed by GitHub
parent d63da14787
commit dc5ad32fb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Ensure data filtered by `woocommerce_logger_log_message` does not carry across multiple log handlers

View File

@ -183,10 +183,10 @@ class WC_Logger implements WC_Logger_Interface {
* @param array $context Additional information for log handlers.
* @param object $handler The handler object, such as WC_Log_Handler_File. Available since 5.3.
*/
$message = apply_filters( 'woocommerce_logger_log_message', $message, $level, $context, $handler );
$filtered_message = apply_filters( 'woocommerce_logger_log_message', $message, $level, $context, $handler );
if ( null !== $message ) {
$handler->handle( $timestamp, $level, $message, $context );
if ( null !== $filtered_message ) {
$handler->handle( $timestamp, $level, $filtered_message, $context );
}
}
}