Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Apply SLF4J best practices #10161

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public Object intercept(MethodInvocationContext<Object, Object> context) {
context.proceed();
} catch (Throwable e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error occurred executing @Async method [" + context.getExecutableMethod() + "]: " + e.getMessage(), e);
LOG.error("Error occurred executing @Async method [{}]: {}", context.getExecutableMethod(), e.getMessage(), e);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public DefaultWatchThread start() {
}
} catch (IOException e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error starting file watch service: " + e.getMessage(), e);
LOG.error("Error starting file watch service: {}", e.getMessage(), e);
}
}
return this;
Expand Down Expand Up @@ -168,7 +168,7 @@ protected void closeWatchService() {
getWatchService().close();
} catch (IOException e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error stopping file watch service: " + e.getMessage(), e);
LOG.error("Error stopping file watch service: {}", e.getMessage(), e);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/io/micronaut/core/io/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public static String readText(BufferedReader reader) throws IOException {
} catch (IOException e) {
Logger logger = LoggerFactory.getLogger(Logger.class);
if (logger.isWarnEnabled()) {
logger.warn("Failed to close reader: " + e.getMessage(), e);
logger.warn("Failed to close reader: {}", e.getMessage(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Optional<?> tryInstantiate(String name, ClassLoader classLoader) {
} catch (Throwable e) {
Logger log = LoggerFactory.getLogger(InstantiationUtils.class);
if (log.isDebugEnabled()) {
log.debug("Tried, but could not instantiate type: " + name, e);
log.debug("Tried, but could not instantiate type: {}", name, e);
}
return Optional.empty();
}
Expand All @@ -81,7 +81,7 @@ public static Optional<?> tryInstantiate(String name, ClassLoader classLoader) {
final Supplier<T> reflectionFallback = () -> {
Logger log = LoggerFactory.getLogger(InstantiationUtils.class);
if (log.isDebugEnabled()) {
log.debug("Tried, but could not instantiate type: " + type);
log.debug("Tried, but could not instantiate type: {}", type);
}
return null;
};
Expand Down Expand Up @@ -156,7 +156,7 @@ public static Optional<?> tryInstantiate(String name, ClassLoader classLoader) {
} catch (Throwable e1) {
Logger log = LoggerFactory.getLogger(InstantiationUtils.class);
if (log.isDebugEnabled()) {
log.debug("Tried, but could not instantiate type: " + type, e);
log.debug("Tried, but could not instantiate type: {}", type, e);
}
return null;
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public static Optional<?> tryInstantiate(String name, ClassLoader classLoader) {
} catch (Throwable e) {
Logger log = ClassUtils.REFLECTION_LOGGER;
if (log.isDebugEnabled()) {
log.debug("Tried, but could not instantiate type: " + type, e);
log.debug("Tried, but could not instantiate type: {}", type, e);
}
return Optional.empty();
}
Expand All @@ -207,7 +207,7 @@ public static <T> T instantiate(Class<T> type) {
try {
Logger log = ClassUtils.REFLECTION_LOGGER;
if (log.isDebugEnabled()) {
log.debug("Reflectively instantiating type: " + type);
log.debug("Reflectively instantiating type: {}", type);
}
return type.getDeclaredConstructor().newInstance();
} catch (Throwable e) {
Expand Down Expand Up @@ -236,7 +236,7 @@ public static <T> T instantiate(Class<T> type, Class<?>[] argTypes, Object... ar
try {
Logger log = ClassUtils.REFLECTION_LOGGER;
if (log.isDebugEnabled()) {
log.debug("Reflectively instantiating type: " + type);
log.debug("Reflectively instantiating type: {}", type);
}
final Constructor<T> declaredConstructor = type.getDeclaredConstructor(argTypes);
declaredConstructor.setAccessible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ public Optional<ComputeInstanceMetadata> resolve(Environment environment) {
}
} catch (MalformedURLException mue) {
if (LOG.isErrorEnabled()) {
LOG.error("Digital Ocean metadataUrl value is invalid!: " + configuration.getUrl(), mue);
LOG.error("Digital Ocean metadataUrl value is invalid!: {}", configuration.getUrl(), mue);
}
} catch (IOException ioe) {
if (LOG.isErrorEnabled()) {
LOG.error("Error connecting to" + configuration.getUrl() + "reading instance metadata", ioe);
LOG.error("Error connecting to{}reading instance metadata", configuration.getUrl(), ioe);
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ protected void doOnError(Throwable t) {
}
}
if (LOG.isErrorEnabled()) {
LOG.error("Client [" + declaringType.getName() + "] received HTTP error response: " + t.getMessage(), t);
LOG.error("Client [{}] received HTTP error response: {}", declaringType.getName(), t.getMessage(), t);
}
future.completeExceptionally(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public void close() throws Exception {
httpClient.close();
} catch (Throwable e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Error shutting down HTTP client: " + e.getMessage(), e);
LOG.warn("Error shutting down HTTP client: {}", e.getMessage(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2201,7 +2201,7 @@ private void forwardResponseToPromise(FullHttpResponse msg) {
} catch (Exception t) {
makeNormalBodyParseError(msg, t, cause -> {
if (!responsePromise.tryFailure(cause) && log.isWarnEnabled()) {
log.warn("Exception fired after handler completed: " + t.getMessage(), t);
log.warn("Exception fired after handler completed: {}", t.getMessage(), t);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void close() {
httpClient.close();
} catch (Throwable e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Error shutting down HTTP client: " + e.getMessage(), e);
LOG.warn("Error shutting down HTTP client: {}", e.getMessage(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public <T> Optional<T> getBody(Argument<T> type) {
throw e;
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Error decoding HTTP error response body: " + e.getMessage(), e);
LOG.debug("Error decoding HTTP error response body: {}", e.getMessage(), e);
}
converted = Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected final void forwardErrorToUser(ChannelHandlerContext ctx, Consumer<Thro
} catch (Exception e) {

if (LOG.isErrorEnabled()) {
LOG.error("Error invoking to @OnError handler " + target.getClass().getSimpleName() + "." + errorMethod.getExecutableMethod() + ": " + e.getMessage(), e);
LOG.error("Error invoking to @OnError handler {}.{}: {}", target.getClass().getSimpleName(), errorMethod.getExecutableMethod(), e.getMessage(), e);
}
fallback.accept(e);
return;
Expand All @@ -233,7 +233,7 @@ protected final void forwardErrorToUser(ChannelHandlerContext ctx, Consumer<Thro
Flux<?> flowable = Flux.from(instrumentPublisher(ctx, result));
flowable.collectList().subscribe(objects -> fallback.accept(cause), throwable -> {
if (throwable != null && LOG.isErrorEnabled()) {
LOG.error("Error subscribing to @OnError handler " + target.getClass().getSimpleName() + "." + errorMethod.getExecutableMethod() + ": " + throwable.getMessage(), throwable);
LOG.error("Error subscribing to @OnError handler {}.{}: {}", target.getClass().getSimpleName(), errorMethod.getExecutableMethod(), throwable.getMessage(), throwable);
}
fallback.accept(cause);
});
Expand Down Expand Up @@ -425,7 +425,7 @@ protected void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame ms
},
error -> {
if (LOG.isErrorEnabled()) {
LOG.error("Error Processing WebSocket Pong Message [" + webSocketBean + "]: " + error.getMessage(), error);
LOG.error("Error Processing WebSocket Pong Message [{}]: {}", webSocketBean, error.getMessage(), error);
}
exceptionCaught(ctx, error);
},
Expand All @@ -434,7 +434,7 @@ protected void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame ms
}
} catch (Throwable e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error Processing WebSocket Message [" + webSocketBean + "]: " + e.getMessage(), e);
LOG.error("Error Processing WebSocket Message [{}]: {}", webSocketBean, e.getMessage(), e);
}
exceptionCaught(ctx, e);
}
Expand All @@ -451,7 +451,7 @@ protected void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame ms

private void messageProcessingException(ChannelHandlerContext ctx, Throwable e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error Processing WebSocket Message [" + webSocketBean + "]: " + e.getMessage(), e);
LOG.error("Error Processing WebSocket Message [{}]: {}", webSocketBean, e.getMessage(), e);
}
exceptionCaught(ctx, e);
}
Expand Down Expand Up @@ -505,7 +505,7 @@ protected void handleCloseReason(ChannelHandlerContext ctx, CloseReason cr, bool
invokeAndClose(ctx, target, boundExecutable, methodExecutionHandle, true);
} catch (Throwable e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error invoking @OnClose handler for WebSocket bean [" + target + "]: " + e.getMessage(), e);
LOG.error("Error invoking @OnClose handler for WebSocket bean [{}]: {}", target, e.getMessage(), e);
}
}
} else {
Expand All @@ -527,7 +527,7 @@ private void invokeAndClose(ChannelHandlerContext ctx, Object target, BoundExecu
result = invokeExecutable(boundExecutable, methodExecutionHandle);
} catch (Exception e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error invoking @OnClose handler " + target.getClass().getSimpleName() + "." + methodExecutionHandle.getExecutableMethod() + ": " + e.getMessage(), e);
LOG.error("Error invoking @OnClose handler {}.{}: {}", target.getClass().getSimpleName(), methodExecutionHandle.getExecutableMethod(), e.getMessage(), e);
}
ctx.close();
return;
Expand All @@ -539,7 +539,7 @@ private void invokeAndClose(ChannelHandlerContext ctx, Object target, BoundExecu

}, throwable -> {
if (throwable != null && LOG.isErrorEnabled()) {
LOG.error("Error subscribing to @" + (isClose ? "OnClose" : "OnError") + " handler for WebSocket bean [" + target + "]: " + throwable.getMessage(), throwable);
LOG.error("Error subscribing to @{} handler for WebSocket bean [{}]: {}", (isClose ? "OnClose" : "OnError"), target, throwable.getMessage(), throwable);
}
ctx.close();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,7 @@ protected EventLoopGroup createWorkerEventLoopGroup(@Nullable EventLoopGroupConf
String configName = workerConfig != null ? workerConfig.getName() : EventLoopGroupConfiguration.DEFAULT;
return nettyEmbeddedServices.getEventLoopGroupRegistry().getEventLoopGroup(configName)
.orElseGet(() -> {
LOG.warn("The configuration for 'micronaut.server.netty.worker.{}' is deprecated. " +
"Use 'micronaut.netty.event-loops.default' configuration instead.", configName);
LOG.warn("The configuration for 'micronaut.server.netty.worker.{}' is deprecated. Use 'micronaut.netty.event-loops.default' configuration instead.", configName);
final EventLoopGroup newGroup = newEventLoopGroup(workerConfig);
shutdownWorker = true;
return newGroup;
Expand Down Expand Up @@ -570,7 +569,7 @@ protected void initChannel(@NonNull Channel ch) {
if (isBindError) {
LOG.error("Unable to start server. Port {} already in use.", displayAddress(cfg));
} else {
LOG.error("Error starting Micronaut server: " + e.getMessage(), e);
LOG.error("Error starting Micronaut server: {}", e.getMessage(), e);
}
}
stopInternal(false);
Expand Down Expand Up @@ -606,7 +605,7 @@ private void fireStartupEvents() {
private void logShutdownErrorIfNecessary(Future<?> future) {
if (!future.isSuccess() && LOG.isWarnEnabled()) {
Throwable e = future.cause();
LOG.warn("Error stopping Micronaut server: " + e.getMessage(), e);
LOG.warn("Error stopping Micronaut server: {}", e.getMessage(), e);
}
}

Expand Down Expand Up @@ -666,7 +665,7 @@ private void stopInternal(boolean stopServerOnly) {
}
} catch (Throwable e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error stopping Micronaut server: " + e.getMessage(), e);
LOG.error("Error stopping Micronaut server: {}", e.getMessage(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void cleanupRequest(NettyHttpRequest<?> request) {
terminateEventPublisher.publishEvent(new HttpRequestTerminatedEvent(request));
} catch (Exception e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error publishing request terminated event: " + e.getMessage(), e);
LOG.error("Error publishing request terminated event: {}", e.getMessage(), e);
}
}
}
Expand All @@ -175,18 +175,18 @@ public void handleUnboundError(Throwable cause) {
// running any filters
if (isIgnorable(cause)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Swallowed an IOException caused by client connectivity: " + cause.getMessage(), cause);
LOG.debug("Swallowed an IOException caused by client connectivity: {}", cause.getMessage(), cause);
}
return;
}

if (cause instanceof SSLException || cause.getCause() instanceof SSLException) {
if (LOG.isDebugEnabled()) {
LOG.debug("Micronaut Server Error - No request state present. Cause: " + cause.getMessage(), cause);
LOG.debug("Micronaut Server Error - No request state present. Cause: {}", cause.getMessage(), cause);
}
} else {
if (LOG.isErrorEnabled()) {
LOG.error("Micronaut Server Error - No request state present. Cause: " + cause.getMessage(), cause);
LOG.error("Micronaut Server Error - No request state present. Cause: {}", cause.getMessage(), cause);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public BindingResult<InputStream> bind(ArgumentConversionContext<InputStream> co
return () -> Optional.of(s);
} catch (ContentLengthExceededException t) {
if (LOG.isTraceEnabled()) {
LOG.trace("Server received error for argument [" + context.getArgument() + "]: " + t.getMessage(), t);
LOG.trace("Server received error for argument [{}]: {}", context.getArgument(), t.getMessage(), t);
}
return BindingResult.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void onError(Throwable t) {
}
} catch (IOException e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Failed to close file stream : " + fileUpload.getName());
LOG.warn("Failed to close file stream : {}", fileUpload.getName());
}
}
}
Expand All @@ -207,7 +207,7 @@ public void onComplete() {
emitter.success(true);
} catch (IOException e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Failed to close file stream : " + fileUpload.getName());
LOG.warn("Failed to close file stream : {}", fileUpload.getName());
}
emitter.success(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
Channel channel = ctx.channel();
channel.attr(NettyWebSocketSession.WEB_SOCKET_SESSION_KEY).set(null);
if (LOG.isDebugEnabled()) {
LOG.debug("Removing WebSocket Server session: " + serverSession);
LOG.debug("Removing WebSocket Server session: {}", serverSession);
}
webSocketSessionRepository.removeChannel(channel);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void writeResponse(ChannelHandlerContext ctx, NettyHttpRequest<?> msg, b

} catch (Throwable e) {
if (LOG.isErrorEnabled()) {
LOG.error("Error opening WebSocket: " + e.getMessage(), e);
LOG.error("Error opening WebSocket: {}", e.getMessage(), e);
}
ctx.writeAndFlush(new CloseWebSocketFrame(CloseReason.INTERNAL_ERROR.getCode(), CloseReason.INTERNAL_ERROR.getReason()));
}
Expand Down
Loading
Loading