Avoid unnecessary stack trace capture (#4663)

Constructing an `AssertionError` is rather expensive, and pointless in
cases that we're not even going to log it. With this commit we skip all
this unnecessary work.

Relates https://github.com/elastic/elasticsearch/issues/89107
This commit is contained in:
David Turner 2022-08-05 19:04:23 +01:00 committed by GitHub
parent 6be22eeaa5
commit cfbe5f9d20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -51,7 +51,9 @@ public final class ValidationUtil {
* <p>Log includes a stack trace.
*/
public static void log(String message, Level level) {
API_USAGE_LOGGER.log(level, message, new AssertionError());
if (API_USAGE_LOGGER.isLoggable(level)) {
API_USAGE_LOGGER.log(level, message, new AssertionError());
}
}
/** Check if the instrument name is valid. If invalid, log a warning. */