Skip to content

Commit

Permalink
Merge pull request #2910 from timtebeek/refactor/parameterized-logging
Browse files Browse the repository at this point in the history
refactor: Parameterized logging with constant log values
  • Loading branch information
smcvb committed Nov 22, 2023
2 parents d7b14cc + 2445b22 commit 2bf65ab
Show file tree
Hide file tree
Showing 31 changed files with 59 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public void configureModule(@Nonnull Configurer configurer) {
configurer.configureQueryBus(this::buildQueryBus);
configurer.registerModule(new EventProcessorInfoConfiguration());
configurer.registerComponent(TokenStore.class, c -> {
logger.warn("BEWARE! Falling back to an in-memory token store. It is highly recommended to configure a " +
"persistent implementation, based on the activity of the handler.");
logger.warn("BEWARE! Falling back to an in-memory token store. It is highly recommended to configure a persistent implementation, based on the activity of the handler.");
return new InMemoryTokenStore();
});
configurer.registerComponent(TargetContextResolver.class, configuration -> TargetContextResolver.noOp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ private <C, R> void doDispatch(CommandMessage<C> commandMessage,
@Override
public Registration subscribe(@Nonnull String commandName,
@Nonnull MessageHandler<? super CommandMessage<?>> messageHandler) {
logger.debug("Subscribing command with name [{}] to this distributed CommandBus. "
+ "Expect similar logging on the local segment.", commandName);
logger.debug("Subscribing command with name [{}] to this distributed CommandBus. Expect similar logging on the local segment.", commandName);
Registration localRegistration = localSegment.subscribe(commandName, messageHandler);
io.axoniq.axonserver.connector.Registration serverRegistration =
axonServerConnectionManager.getConnection(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ public CommandResponse serialize(CommandResultMessage<?> commandResultMessage, S
responseBuilder.setPayload(objectSerializer.apply(optionalDetails.get()));
} else {
logger.warn("Serializing exception [{}] without details.", throwable.getClass(), throwable);
logger.info("To share exceptional information with the recipient it is recommended to wrap the "
+ "exception in a CommandExecutionException with provided details.");
logger.info("To share exceptional information with the recipient it is recommended to wrap the exception in a CommandExecutionException with provided details.");
}
} else if (commandResultMessage.getPayload() != null) {
responseBuilder.setPayload(objectSerializer.apply(commandResultMessage.getPayload()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,7 @@ protected void storeSnapshot(DomainEventMessage<?> snapshot, Serializer serializ
logger.debug("Snapshot created for aggregate type {}, identifier {}",
snapshot.getType(), snapshot.getAggregateIdentifier());
} else {
logger.warn("Snapshot creation failed for unknown reason. "
+ "Check server logs for details.");
logger.warn("Snapshot creation failed for unknown reason. Check server logs for details.");
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ private void setLoadBalancingStrategies(AxonServerConnection connection, Set<Str
.stream()
.filter(entry -> {
if (!processorNames.contains(entry.getKey())) {
logger.info("Event Processor [{}] is not a registered. "
+ "Please check the name or register the Event Processor",
entry.getKey());
logger.info("Event Processor [{}] is not a registered. Please check the name or register the Event Processor", entry.getKey());
return false;
}
return true;
Expand All @@ -185,8 +183,7 @@ private void setLoadBalancingStrategies(AxonServerConnection connection, Set<Str
strategiesPerProcessor.forEach((processorName, strategy) -> {
Optional<String> optionalIdentifier = tokenStoreIdentifierFor(processorName);
if (!optionalIdentifier.isPresent()) {
logger.warn("Cannot find token store identifier for processor [{}]. "
+ "Load balancing cannot be configured without this identifier.", processorName);
logger.warn("Cannot find token store identifier for processor [{}]. Load balancing cannot be configured without this identifier.", processorName);
return;
}
String tokenStoreIdentifier = optionalIdentifier.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ public QueryResponse serializeResponse(QueryResponseMessage<?> queryResponse, St
responseBuilder.setPayload(exceptionDetailsSerializer.apply(optionalDetails.get()));
} else {
logger.warn("Serializing exception [{}] without details.", exceptionResult.getClass(), exceptionResult);
logger.info("To share exceptional information with the recipient it is recommended to wrap the "
+ "exception in a QueryExecutionException with provided details.");
logger.info("To share exceptional information with the recipient it is recommended to wrap the exception in a QueryExecutionException with provided details.");
}
} else {
responseBuilder.setPayload(payloadSerializer.apply(queryResponse));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ public QueryUpdate serialize(SubscriptionQueryUpdateMessage<?> subscriptionQuery
updateMessageBuilder.setPayload(exceptionDetailsSerializer.apply(optionalDetails.get()));
} else {
logger.warn("Serializing exception [{}] without details.", exceptionResult.getClass(), exceptionResult);
logger.info("To share exceptional information with the recipient it is recommended to wrap the "
+ "exception in a QueryExecutionException with provided details.");
logger.info("To share exceptional information with the recipient it is recommended to wrap the exception in a QueryExecutionException with provided details.");
}
} else {
updateMessageBuilder.setPayload(payloadSerializer.apply(subscriptionQueryUpdateMessage));
Expand Down Expand Up @@ -251,8 +250,7 @@ QueryProviderOutbound serialize(QueryResponseMessage<?> initialResult, String su
responseBuilder.setPayload(exceptionDetailsSerializer.apply(optionalDetails.get()));
} else {
logger.warn("Serializing exception [{}] without details.", exceptionResult.getClass(), exceptionResult);
logger.info("To share exceptional information with the recipient it is recommended to wrap the "
+ "exception in a QueryExecutionException with provided details.");
logger.info("To share exceptional information with the recipient it is recommended to wrap the exception in a QueryExecutionException with provided details.");
}
} else {
responseBuilder.setPayload(payloadSerializer.apply(initialResult));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,17 +1062,15 @@ private void invokeLifecycleHandlers(TreeMap<Integer, List<LifecycleHandler>> li
exceptionHandler.accept(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
logger.warn(String.format(
"Completion interrupted during %s phase [%d]. Proceeding to following phase",
lifecycleState.description, currentLifecyclePhase
));
logger.warn(
"Completion interrupted during {} phase [{}]. Proceeding to following phase",
lifecycleState.description, currentLifecyclePhase);
} catch (TimeoutException e) {
final long lifecyclePhaseTimeoutInSeconds = TimeUnit.SECONDS.convert(lifecyclePhaseTimeout,
lifecyclePhaseTimeunit);
logger.warn(String.format(
"Timed out during %s phase [%d] after %d second(s). Proceeding to following phase",
lifecycleState.description, currentLifecyclePhase, lifecyclePhaseTimeoutInSeconds
));
logger.warn(
"Timed out during {} phase [{}] after {} second(s). Proceeding to following phase",
lifecycleState.description, currentLifecyclePhase, lifecyclePhaseTimeoutInSeconds);
}
} while ((phasedHandlers = lifecycleHandlerMap.higherEntry(currentLifecyclePhase)) != null);
currentLifecyclePhase = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ public void run() {
if (logger.isDebugEnabled()) {
logger.warn("An attempt to create and store a snapshot resulted in an exception:", e);
} else {
logger.warn("An attempt to create and store a snapshot resulted in an exception. " +
"Exception summary: {}", e.getMessage());
logger.warn("An attempt to create and store a snapshot resulted in an exception. Exception summary: {}", e.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,7 @@ public void run() {
return;
}
tailingConsumers.stream().filter(EventConsumer::behindGlobalCache).forEach(consumer -> {
logger.debug("An event stream cannot read from the local cache. It either runs behind, or its " +
"current token cannot be found in the cache. Opening a dedicated stream.");
logger.debug("An event stream cannot read from the local cache. It either runs behind, or its current token cannot be found in the cache. Opening a dedicated stream.");
consumer.stopTailingGlobalStream();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,7 @@ private GapAwareTrackingToken cleanGaps(TrackingToken lastToken) {
cleanToken = cleanToken.withGapsTruncatedAt(sequenceNumber);
}
} catch (DateTimeParseException e) {
logger.info("Unable to parse timestamp to clean old gaps. "
+ "Tokens may contain large numbers of gaps, decreasing Tracking performance.");
logger.info("Unable to parse timestamp to clean old gaps. Tokens may contain large numbers of gaps, decreasing Tracking performance.");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,7 @@ public void run() {
return;
}
tailingConsumers.stream().filter(EventConsumer::behindGlobalCache).forEach(consumer -> {
logger.debug("An event stream cannot read from the local cache. It either runs behind, or its " +
"current token cannot be found in the cache. Opening a dedicated stream.");
logger.debug("An event stream cannot read from the local cache. It either runs behind, or its current token cannot be found in the cache. Opening a dedicated stream.");
consumer.stopTailingGlobalStream();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ private <C> CommandMessage<? extends C> intercept(CommandMessage<C> command) {
@Override
public Registration subscribe(@Nonnull String commandName,
@Nonnull MessageHandler<? super CommandMessage<?>> handler) {
logger.debug("Subscribing command with name [{}] to this distributed CommandBus. "
+ "Expect similar logging on the local segment.", commandName);
logger.debug("Subscribing command with name [{}] to this distributed CommandBus. Expect similar logging on the local segment.", commandName);
Registration reg = connector.subscribe(commandName, handler);
updateFilter(commandFilter.get().or(new CommandNameFilter(commandName)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ private static IdentifierFactory locateFactories(ClassLoader classLoader, String
logger.debug("Found IdentifierFactory implementation using the {} Class Loader", classLoaderName);
found = services.next();
if (services.hasNext()) {
logger.warn("More than one IdentifierFactory implementation was found using the {} "
+ "Class Loader. This may result in different selections being made after "
+ "restart of the application.", classLoaderName);
logger.warn("More than one IdentifierFactory implementation was found using the {} Class Loader. This may result in different selections being made after restart of the application.", classLoaderName);
}
}
return found;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private static Class<?> erase(Type type) {
} else if (type instanceof GenericArrayType) {
return Array.newInstance(erase(((GenericArrayType) type).getGenericComponentType()), 0).getClass();
}
logger.debug(type.getClass() + " is not supported for type erasure. Will by default return Object.");
logger.debug("{} is not supported for type erasure. Will by default return Object.", type.getClass());
return Object.class;
}

Expand All @@ -127,10 +127,7 @@ private static Type[] getExactDirectSuperTypes(Type type) {
throw new IllegalArgumentException("Cannot handle given Type of null");
}

logger.debug(
type.getClass() + " is not supported for retrieving the exact direct super types from. Will by "
+ "default return the type contained in an Type[]"
);
logger.debug("{} is not supported for retrieving the exact direct super types from. Will by default return the type contained in an Type[]", type.getClass());
return new Type[]{type};
}

Expand Down Expand Up @@ -216,10 +213,7 @@ private static boolean isMissingTypeParameters(Type type) {
} else if (type instanceof ParameterizedType) {
return false;
} else {
logger.debug(
type.getClass() + " is not supported for checking if there are missing type parameters. "
+ "Will by default return false."
);
logger.debug("{} is not supported for checking if there are missing type parameters. Will by default return false.", type.getClass());
return false;
}
}
Expand Down Expand Up @@ -266,9 +260,7 @@ private Type map(Type type) {
return new ParameterizedTypeImpl((Class<?>) pType.getRawType(), actualTypeArguments, ownerType);
}

logger.debug(
type.getClass() + " is not supported for variable mapping. Will by default return the type as is."
);
logger.debug("{} is not supported for variable mapping. Will by default return the type as is.", type.getClass());
return type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ private void processBatch(Segment segment, BlockingStream<TrackedEventMessage<?>
checkSegmentCaughtUp(segment, eventStream);
} catch (InterruptedException e) {
if (isRunning()) {
logger.error(String.format("Event processor [%s] was interrupted. Shutting down.", getName()), e);
logger.error("Event processor [{}] was interrupted. Shutting down.", getName(), e);
setShutdownState();
}
Thread.currentThread().interrupt();
Expand Down Expand Up @@ -767,10 +767,7 @@ private CompletableFuture<Void> awaitTermination() {
workerThread.interrupt();
workerThread.join(workerTerminationTimeout);
if (workerThread.isAlive()) {
logger.warn(
"Forced shutdown of Tracking Processor Worker '{}' was unsuccessful. "
+ "Consider increasing workerTerminationTimeout.",
worker.getKey()
logger.warn("Forced shutdown of Tracking Processor Worker '{}' was unsuccessful. Consider increasing workerTerminationTimeout.", worker.getKey()
);
}
}
Expand Down Expand Up @@ -1324,10 +1321,7 @@ public void run() {
});
} catch (UnableToClaimTokenException ucte) {
// When not able to claim a token for a given segment, we skip the
logger.debug(
"Unable to claim the token for segment: {}. "
+ "It is owned by another process or has been split/merged concurrently",
segmentId
logger.debug("Unable to claim the token for segment: {}. It is owned by another process or has been split/merged concurrently", segmentId
);

TrackerStatus removedStatus = activeSegments.remove(segmentId);
Expand Down
Loading

0 comments on commit 2bf65ab

Please sign in to comment.