Skip to content

Commit

Permalink
Add new filter to disable query logging: ep_disable_query_logging (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahum authored Dec 3, 2024
1 parent 8a2f419 commit a66065a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions includes/classes/Elasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -1618,12 +1618,25 @@ public function add_elasticpress_version_to_user_agent( $user_agent ) {
* Query logging. Don't log anything to the queries property when
* WP_DEBUG is not enabled. Calls action 'ep_add_query_log' if you
* want to access the query outside of the ElasticPress plugin. This
* runs regardless of debufg settings.
* runs regardless of debug settings.
*
* @param array $query Query to log.
*/
protected function add_query_log( $query ) {
if ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || ( defined( 'WP_EP_DEBUG' ) && WP_EP_DEBUG ) ) {
$wp_debug = defined( 'WP_DEBUG' ) && WP_DEBUG;
$wp_ep_debug = defined( 'WP_EP_DEBUG' ) && WP_EP_DEBUG;

/**
* Filter query logging. Don't log anything to the queries property when true.
*
* @hook ep_disable_query_logging
* @param {bool} Whether to log to the queries property. Defaults to false.
* @return {bool} New value
* @since 5.2.0
*/
$disable_query_logging = apply_filters( 'ep_disable_query_logging', false );

if ( ! $disable_query_logging && ( $wp_debug || $wp_ep_debug ) ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_wp_debug_backtrace_summary
$query['backtrace'] = wp_debug_backtrace_summary( null, 1, false ); // VIP: Search Dev Tools relies on this backtrace
$this->queries[] = $query;
Expand Down

0 comments on commit a66065a

Please sign in to comment.