10up / ElasticPress

A fast and flexible search and query engine for WordPress.
https://elasticpress.io
GNU General Public License v2.0
1.23k stars 312 forks source link

Failed Queries Log disable #3916

Closed ws256 closed 1 month ago

ws256 commented 2 months ago

Describe your question

Hello! How to disable query logging? I have some requests with a time exceeding 5s. I can’t repeat it, but 10+ requests per day are written to the log. If you try to repeat the request, it will be completed quickly. I don't know why they are fixed. Example: Time Spent (ms) 5003.54790687561

Code of Conduct

felipeelia commented 1 month ago

You have a couple of ways to achieve that, @ws256:

Disable it completely

You can use the ep_query_logger_queries_to_keep filter to make it never log anything:

add_filter( 'ep_query_logger_queries_to_keep', '__return_zero' );

Conditionally log queries

You can also use the ep_query_logger_should_log_query to decide if a query should or should not be logged. See this line of code to see how the filter works.

Replace the QueryLogger class

If you want to change how the query logging mechanism works, you can replace the default QueryLogger object instance with something custom, using the ep_query_logger filter. This is the related line.