Skip to content

Commit

Permalink
HSEARCH-798 Remove inline logging statements
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Nov 20, 2024
1 parent 22fd83f commit 32fa19d
Show file tree
Hide file tree
Showing 54 changed files with 507 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ private void sign(HttpRequest request, HttpContext context, HttpEntityContentStr
SdkHttpFullRequest awsRequest = toAwsRequest( request, context, contentStreamProvider );

if ( AWS_LOGGER.isTraceEnabled() ) {
AWS_LOGGER.tracef( "HTTP request (before signing): %s", request );
AWS_LOGGER.tracef( "AWS request (before signing): %s", awsRequest );
AWS_LOGGER.httpRequestBeforeSigning( request );
AWS_LOGGER.awsRequestBeforeSigning( awsRequest );
}

AwsCredentials credentials = credentialsProvider.resolveCredentials();
AWS_LOGGER.tracef( "AWS credentials: %s", credentials );
AWS_LOGGER.awsCredentials( credentials );

SignedRequest signedRequest = signer.sign( r -> r.identity( credentials )
.request( awsRequest )
Expand All @@ -89,8 +89,8 @@ private void sign(HttpRequest request, HttpContext context, HttpEntityContentStr
}

if ( AWS_LOGGER.isTraceEnabled() ) {
AWS_LOGGER.tracef( "AWS request (after signing): %s", signedRequest );
AWS_LOGGER.tracef( "HTTP request (after signing): %s", request );
AWS_LOGGER.httpRequestAfterSigning( signedRequest );
AWS_LOGGER.awsRequestAfterSigning( request );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void configure(ElasticsearchHttpClientConfigurationContext context) {
ConfigurationPropertySource propertySource = context.configurationPropertySource();

if ( !SIGNING_ENABLED.get( propertySource ) ) {
AWS_LOGGER.debug( "AWS request signing is disabled." );
AWS_LOGGER.signingDisabled();
return;
}

Expand All @@ -77,8 +77,7 @@ public void configure(ElasticsearchHttpClientConfigurationContext context) {
}
AwsCredentialsProvider credentialsProvider = createCredentialsProvider( context.beanResolver(), propertySource );

AWS_LOGGER.debugf( "AWS request signing is enabled [region = '%s', service = '%s', credentialsProvider = '%s'].",
region, service, credentialsProvider );
AWS_LOGGER.signingEnabled( region, service, credentialsProvider );

AwsSigningRequestInterceptor signingInterceptor =
new AwsSigningRequestInterceptor( region, service, credentialsProvider );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

package org.hibernate.search.backend.elasticsearch.aws.logging.impl;

import static org.jboss.logging.Logger.Level.DEBUG;
import static org.jboss.logging.Logger.Level.TRACE;

import java.lang.invoke.MethodHandles;

import org.hibernate.search.util.common.SearchException;
Expand All @@ -13,11 +16,19 @@
import org.hibernate.search.util.common.logging.impl.MessageConstants;

import org.jboss.logging.BasicLogger;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.jboss.logging.annotations.ValidIdRange;
import org.jboss.logging.annotations.ValidIdRanges;

import org.apache.http.HttpRequest;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.http.SdkHttpFullRequest;
import software.amazon.awssdk.http.auth.spi.signer.SignedRequest;
import software.amazon.awssdk.regions.Region;

@CategorizedLogger(
category = AwsLog.CATEGORY_NAME,
description = """
Expand Down Expand Up @@ -63,4 +74,32 @@ SearchException obsoleteAccessKeyIdOrSecretAccessKeyForSigning(String legacyAcce
String credentialsTypePropertyKey, String credentialsTypePropertyValueStatic,
String accessKeyIdPropertyKey, String secretAccessKeyPropertyKey);

@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 3, value = "HTTP request (before signing): %s")
void httpRequestBeforeSigning(HttpRequest request);

@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 4, value = "AWS request (before signing): %s")
void awsRequestBeforeSigning(SdkHttpFullRequest awsRequest);

@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 5, value = "AWS credentials: %s")
void awsCredentials(AwsCredentials credentials);

@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 6, value = "AWS request (after signing): %s")
void httpRequestAfterSigning(SignedRequest signedRequest);

@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 7, value = "HTTP request (after signing): %s")
void awsRequestAfterSigning(HttpRequest request);

@LogMessage(level = DEBUG)
@Message(id = ID_OFFSET + 8, value = "AWS request signing is disabled.")
void signingDisabled();

@LogMessage(level = DEBUG)
@Message(id = ID_OFFSET + 9,
value = "AWS request signing is enabled [region = '%s', service = '%s', credentialsProvider = '%s'].")
void signingEnabled(Region region, String service, AwsCredentialsProvider credentialsProvider);
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ public BackendImplementor create(EventContext eventContext, BackendBuildContext
CLIENT_FACTORY.getAndMap( propertySource, beanResolver::resolve );
if ( customClientFactoryHolderOptional.isPresent() ) {
clientFactoryHolder = customClientFactoryHolderOptional.get();
CONFIGURATION_LOGGER.debugf(
"Elasticsearch backend will use client factory '%s'. Context: %s",
clientFactoryHolder, eventContext.render()
);
CONFIGURATION_LOGGER.backendClientFactory( clientFactoryHolder, eventContext.render() );
}
else {
clientFactoryHolder = BeanHolder.of( new ElasticsearchClientFactoryImpl() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class IndexNames {
public static String normalizeName(String indexName) {
String esIndexName = indexName.toLowerCase( Locale.ENGLISH );
if ( !esIndexName.equals( indexName ) ) {
MAPPING_LOGGER.debugf( "Normalizing index name from '%1$s' to '%2$s'", indexName, esIndexName );
MAPPING_LOGGER.normalizeIndexName( indexName, esIndexName );
}
return esIndexName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@

import static org.hibernate.search.backend.elasticsearch.logging.impl.ElasticsearchLog.ID_OFFSET;
import static org.hibernate.search.backend.elasticsearch.logging.impl.ElasticsearchLog.ID_OFFSET_LEGACY_ES;
import static org.jboss.logging.Logger.Level.DEBUG;

import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.Set;

import org.hibernate.search.engine.environment.bean.BeanHolder;
import org.hibernate.search.util.common.SearchException;
import org.hibernate.search.util.common.logging.CategorizedLogger;
import org.hibernate.search.util.common.logging.impl.LoggerFactory;
import org.hibernate.search.util.common.logging.impl.MessageConstants;
import org.hibernate.search.util.common.reporting.EventContext;

import org.jboss.logging.BasicLogger;
import org.jboss.logging.annotations.Cause;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.jboss.logging.annotations.Param;
Expand All @@ -30,7 +32,7 @@
"""
)
@MessageLogger(projectCode = MessageConstants.PROJECT_CODE)
public interface ConfigurationLog extends BasicLogger {
public interface ConfigurationLog {
String CATEGORY_NAME = "org.hibernate.search.configuration";

ConfigurationLog CONFIGURATION_LOGGER = LoggerFactory.make( ConfigurationLog.class, CATEGORY_NAME, MethodHandles.lookup() );
Expand Down Expand Up @@ -114,4 +116,9 @@ public interface ConfigurationLog extends BasicLogger {
value = "Invalid backend configuration: mapping requires single-tenancy"
+ " but multi-tenancy strategy is set.")
SearchException multiTenancyNotRequiredButExplicitlyEnabledByTheBackend();

@LogMessage(level = DEBUG)
@Message(id = ID_OFFSET + 192,
value = "Elasticsearch backend will use client factory '%s'. Context: %s")
void backendClientFactory(BeanHolder<?> clientFactoryHolder, String eventContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public interface ElasticsearchLog
* here to the next value.
*/
@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 191, value = "")
@Message(id = ID_OFFSET + 193, value = "")
void nextLoggerIdForConvenience();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.hibernate.search.backend.elasticsearch.logging.impl;

import static org.hibernate.search.backend.elasticsearch.logging.impl.ElasticsearchLog.ID_OFFSET;
import static org.jboss.logging.Logger.Level.DEBUG;

import java.lang.invoke.MethodHandles;
import java.util.Set;
Expand All @@ -20,9 +21,9 @@
import org.hibernate.search.util.common.logging.impl.MessageConstants;
import org.hibernate.search.util.common.reporting.EventContext;

import org.jboss.logging.BasicLogger;
import org.jboss.logging.annotations.Cause;
import org.jboss.logging.annotations.FormatWith;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.jboss.logging.annotations.Param;
Expand All @@ -34,7 +35,7 @@
"""
)
@MessageLogger(projectCode = MessageConstants.PROJECT_CODE)
public interface MappingLog extends BasicLogger {
public interface MappingLog {
String CATEGORY_NAME = "org.hibernate.search.mapping";

MappingLog MAPPING_LOGGER = LoggerFactory.make( MappingLog.class, CATEGORY_NAME, MethodHandles.lookup() );
Expand Down Expand Up @@ -153,4 +154,8 @@ SearchException cannotGuessVectorFieldType(@FormatWith(ClassFormatter.class) Cla
value = "The OpenSearch distribution does not allow using %1$s as a space type for a Lucene engine."
+ " Try using a different similarity type and refer to the OpenSearch documentation for more details.")
SearchException vectorSimilarityNotSupportedByOpenSearchBackend(VectorSimilarity vectorSimilarity);

@LogMessage(level = DEBUG)
@Message(id = ID_OFFSET + 191, value = "Normalizing index name from '%1$s' to '%2$s'")
void normalizeIndexName(String indexName, String esIndexName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private Version getLuceneVersion(EventContext backendContext, ConfigurationPrope
if ( luceneVersionOptional.isPresent() ) {
luceneVersion = luceneVersionOptional.get();
if ( CONFIGURATION_LOGGER.isDebugEnabled() ) {
CONFIGURATION_LOGGER.debug( "Setting Lucene compatibility to Version " + luceneVersion );
CONFIGURATION_LOGGER.luceneCompatibilityVersion( luceneVersion );
}
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.hibernate.search.util.common.reporting.EventContext;

import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.Cause;
import org.jboss.logging.annotations.FormatWith;
import org.jboss.logging.annotations.LogMessage;
Expand Down Expand Up @@ -124,4 +125,7 @@ void recommendConfiguringLuceneVersion(String key, Version latest,
+ " but multi-tenancy strategy is set.")
SearchException multiTenancyNotRequiredButExplicitlyEnabledByTheBackend();

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = ID_OFFSET + 188, value = "Setting Lucene compatibility to Version %s")
void luceneCompatibilityVersion(Version luceneVersion);
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public interface LuceneLog
* here to the next value.
*/
@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 188, value = "")
@Message(id = ID_OFFSET + 194, value = "")
void nextLoggerIdForConvenience();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

import static org.hibernate.search.backend.lucene.logging.impl.LuceneLog.ID_OFFSET;
import static org.hibernate.search.backend.lucene.logging.impl.LuceneLog.ID_OFFSET_LEGACY_ENGINE;
import static org.jboss.logging.Logger.Level.DEBUG;
import static org.jboss.logging.Logger.Level.INFO;
import static org.jboss.logging.Logger.Level.TRACE;
import static org.jboss.logging.Logger.Level.WARN;

import java.lang.invoke.MethodHandles;
import java.nio.file.Path;

import org.hibernate.search.backend.lucene.lowlevel.reader.impl.HibernateSearchMultiReader;
import org.hibernate.search.util.common.SearchException;
import org.hibernate.search.util.common.logging.CategorizedLogger;
import org.hibernate.search.util.common.logging.impl.EventContextFormatter;
Expand Down Expand Up @@ -137,4 +140,24 @@ SearchException uncommittedOperationsBecauseOfFailure(String causeMessage,
@Message(id = ID_OFFSET + 187,
value = "Unable to refresh an index reader: %1$s")
SearchException unableToRefresh(String causeMessage, @Param EventContext context, @Cause Exception cause);

@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 189, value = "Closing MultiReader: %s")
void closingMultiReader(HibernateSearchMultiReader hibernateSearchMultiReader);

@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 190, value = "MultiReader closed: %s")
void closedMultiReader(HibernateSearchMultiReader hibernateSearchMultiReader);

@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 191, value = "IndexWriter closed")
void closedIndexWriter();

@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 192, value = "IndexWriter opened")
void openedIndexWriter();

@LogMessage(level = DEBUG)
@Message(id = ID_OFFSET + 193, value = "Set index writer parameter %s to value : %s. %s")
void indexWriterSetParameter(String settingName, Object value, String context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public IndexReaderMetadataResolver getMetadataResolver() {
protected synchronized void doClose() throws IOException {
final boolean traceEnabled = LUCENE_SPECIFIC_LOGGER.isTraceEnabled();
if ( traceEnabled ) {
LUCENE_SPECIFIC_LOGGER.tracef( "Closing MultiReader: %s", this );
LUCENE_SPECIFIC_LOGGER.closingMultiReader( this );
}
try ( Closer<IOException> closer = new Closer<>() ) {
/*
Expand All @@ -87,7 +87,7 @@ protected synchronized void doClose() throws IOException {
closer.pushAll( DirectoryReader::decRef, directoryReaders );
}
if ( traceEnabled ) {
LUCENE_SPECIFIC_LOGGER.trace( "MultiReader closed." );
LUCENE_SPECIFIC_LOGGER.closedMultiReader( this );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void close() throws IOException {
finally {
commitLock.unlock();
}
LUCENE_SPECIFIC_LOGGER.trace( "IndexWriter closed" );
LUCENE_SPECIFIC_LOGGER.closedIndexWriter();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public IndexWriterDelegatorImpl getOrCreate() throws IOException {
failureHandler,
this::clearAfterFailure
);
LUCENE_SPECIFIC_LOGGER.trace( "IndexWriter opened" );
LUCENE_SPECIFIC_LOGGER.openedIndexWriter();
currentWriter.set( indexWriterDelegator );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ private IndexWriterSettingValue<R> createValueOrNull(T value, EventContext event
return null;
}
if ( LUCENE_SPECIFIC_LOGGER.isDebugEnabled() ) {
LUCENE_SPECIFIC_LOGGER.debugf( "Set index writer parameter %s to value : %s. %s",
settingName, value, eventContext.renderWithPrefix() );
LUCENE_SPECIFIC_LOGGER.indexWriterSetParameter( settingName, value, eventContext.renderWithPrefix() );
}
R processedValue = processor.apply( value );
return new IndexWriterSettingValue<>( settingName, processedValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public CompletableFuture<?> work() {
int workCount = workBuffer.size();
boolean traceEnabled = EXECUTOR_LOGGER.isTraceEnabled();
if ( traceEnabled ) {
EXECUTOR_LOGGER.tracef( "Processing %d works in executor '%s'", workCount, name );
EXECUTOR_LOGGER.numberOfWorksInExecutor( workCount, name );
}

processor.beginBatch();
Expand All @@ -193,7 +193,7 @@ public CompletableFuture<?> work() {
CompletableFuture<?> future = processor.endBatch();
if ( traceEnabled ) {
future.whenComplete( (result, throwable) -> {
EXECUTOR_LOGGER.tracef( "Processed %d works in executor '%s'", workCount, name );
EXECUTOR_LOGGER.numberOfProcessedWorksInExecutor( workCount, name );
} );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void ensureScheduled() {
return;
}

EXECUTOR_LOGGER.tracef( "Scheduling task '%s'.", name );
EXECUTOR_LOGGER.schedulingTask( name );

/*
* Our thread successfully switched the status:
Expand Down Expand Up @@ -191,7 +191,7 @@ public void run() {
needsRun = false;
nextExecutionFuture = null;
try {
EXECUTOR_LOGGER.tracef( "Running task '%s'", name );
EXECUTOR_LOGGER.runningTask( name );
worker.work().handle( workFinishedHandler );
}
catch (Throwable e) {
Expand Down Expand Up @@ -220,7 +220,7 @@ private void afterRun() {

// First, tell the worker that we're done.
try {
EXECUTOR_LOGGER.tracef( "Completed task '%s'", name );
EXECUTOR_LOGGER.completedTask( name );
worker.complete();
}
catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public interface EngineLog
* here to the next value.
*/
@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 130, value = "")
@Message(id = ID_OFFSET + 135, value = "")
void nextLoggerIdForConvenience();
}
Loading

0 comments on commit 32fa19d

Please sign in to comment.