From a8d0541b08b29822c342f3e096b376376e71a305 Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Tue, 26 Dec 2023 22:24:29 +0800 Subject: [PATCH] fix(connector): use log4j's string interpolation (#14206) Signed-off-by: Bugen Zhao --- java/connector-node/tracing/pom.xml | 4 + .../tracing/TracingSlf4jAdapter.java | 156 ++++++++++++++---- src/utils/runtime/src/logger.rs | 1 + 3 files changed, 130 insertions(+), 31 deletions(-) diff --git a/java/connector-node/tracing/pom.xml b/java/connector-node/tracing/pom.xml index 29ed2a08fa50..01ba0b6bbe18 100644 --- a/java/connector-node/tracing/pom.xml +++ b/java/connector-node/tracing/pom.xml @@ -27,6 +27,10 @@ org.slf4j slf4j-api + + org.apache.logging.log4j + log4j-core + diff --git a/java/connector-node/tracing/src/main/java/com/risingwave/tracing/TracingSlf4jAdapter.java b/java/connector-node/tracing/src/main/java/com/risingwave/tracing/TracingSlf4jAdapter.java index 25527a6c7e69..a3a1e752cd3e 100644 --- a/java/connector-node/tracing/src/main/java/com/risingwave/tracing/TracingSlf4jAdapter.java +++ b/java/connector-node/tracing/src/main/java/com/risingwave/tracing/TracingSlf4jAdapter.java @@ -17,6 +17,9 @@ package com.risingwave.tracing; +// Import log4j's ParameterizedMessage, so that we can format the messages +// with the same interpolation as log4j (i.e. "{}" instead of "%s"). +import org.apache.logging.log4j.message.ParameterizedMessage; import org.slf4j.Logger; import org.slf4j.Marker; @@ -45,17 +48,27 @@ public void trace(String msg) { @Override public void trace(String format, Object arg) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.TRACE, String.format(format, arg)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.TRACE, + new ParameterizedMessage(format, arg).getFormattedMessage()); } @Override public void trace(String format, Object arg1, Object arg2) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.TRACE, String.format(format, arg1, arg2)); + new ParameterizedMessage(format, arg1, arg2).getFormattedMessage(); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.TRACE, + new ParameterizedMessage(format, arg1, arg2).getFormattedMessage()); } @Override public void trace(String format, Object... arguments) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.TRACE, String.format(format, arguments)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.TRACE, + new ParameterizedMessage(format, arguments).getFormattedMessage()); } @Override @@ -76,17 +89,26 @@ public void trace(Marker marker, String msg) { @Override public void trace(Marker marker, String format, Object arg) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.TRACE, String.format(format, arg)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.TRACE, + new ParameterizedMessage(format, arg).getFormattedMessage()); } @Override public void trace(Marker marker, String format, Object arg1, Object arg2) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.TRACE, String.format(format, arg1, arg2)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.TRACE, + new ParameterizedMessage(format, arg1, arg2).getFormattedMessage()); } @Override - public void trace(Marker marker, String format, Object... argArray) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.TRACE, String.format(format, argArray)); + public void trace(Marker marker, String format, Object... arguments) { + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.TRACE, + new ParameterizedMessage(format, arguments).getFormattedMessage()); } @Override @@ -107,17 +129,26 @@ public void debug(String msg) { @Override public void debug(String format, Object arg) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.DEBUG, String.format(format, arg)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.DEBUG, + new ParameterizedMessage(format, arg).getFormattedMessage()); } @Override public void debug(String format, Object arg1, Object arg2) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.DEBUG, String.format(format, arg1, arg2)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.DEBUG, + new ParameterizedMessage(format, arg1, arg2).getFormattedMessage()); } @Override public void debug(String format, Object... arguments) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.DEBUG, String.format(format, arguments)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.DEBUG, + new ParameterizedMessage(format, arguments).getFormattedMessage()); } @Override @@ -138,17 +169,26 @@ public void debug(Marker marker, String msg) { @Override public void debug(Marker marker, String format, Object arg) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.DEBUG, String.format(format, arg)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.DEBUG, + new ParameterizedMessage(format, arg).getFormattedMessage()); } @Override public void debug(Marker marker, String format, Object arg1, Object arg2) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.DEBUG, String.format(format, arg1, arg2)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.DEBUG, + new ParameterizedMessage(format, arg1, arg2).getFormattedMessage()); } @Override public void debug(Marker marker, String format, Object... arguments) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.DEBUG, String.format(format, arguments)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.DEBUG, + new ParameterizedMessage(format, arguments).getFormattedMessage()); } @Override @@ -169,17 +209,26 @@ public void info(String msg) { @Override public void info(String format, Object arg) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.INFO, String.format(format, arg)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.INFO, + new ParameterizedMessage(format, arg).getFormattedMessage()); } @Override public void info(String format, Object arg1, Object arg2) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.INFO, String.format(format, arg1, arg2)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.INFO, + new ParameterizedMessage(format, arg1, arg2).getFormattedMessage()); } @Override public void info(String format, Object... arguments) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.INFO, String.format(format, arguments)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.INFO, + new ParameterizedMessage(format, arguments).getFormattedMessage()); } @Override @@ -200,17 +249,26 @@ public void info(Marker marker, String msg) { @Override public void info(Marker marker, String format, Object arg) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.INFO, String.format(format, arg)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.INFO, + new ParameterizedMessage(format, arg).getFormattedMessage()); } @Override public void info(Marker marker, String format, Object arg1, Object arg2) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.INFO, String.format(format, arg1, arg2)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.INFO, + new ParameterizedMessage(format, arg1, arg2).getFormattedMessage()); } @Override public void info(Marker marker, String format, Object... arguments) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.INFO, String.format(format, arguments)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.INFO, + new ParameterizedMessage(format, arguments).getFormattedMessage()); } @Override @@ -231,17 +289,26 @@ public void warn(String msg) { @Override public void warn(String format, Object arg) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.WARN, String.format(format, arg)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.WARN, + new ParameterizedMessage(format, arg).getFormattedMessage()); } @Override public void warn(String format, Object... arguments) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.WARN, String.format(format, arguments)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.WARN, + new ParameterizedMessage(format, arguments).getFormattedMessage()); } @Override public void warn(String format, Object arg1, Object arg2) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.WARN, String.format(format, arg1, arg2)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.WARN, + new ParameterizedMessage(format, arg1, arg2).getFormattedMessage()); } @Override @@ -262,17 +329,26 @@ public void warn(Marker marker, String msg) { @Override public void warn(Marker marker, String format, Object arg) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.WARN, String.format(format, arg)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.WARN, + new ParameterizedMessage(format, arg).getFormattedMessage()); } @Override public void warn(Marker marker, String format, Object arg1, Object arg2) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.WARN, String.format(format, arg1, arg2)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.WARN, + new ParameterizedMessage(format, arg1, arg2).getFormattedMessage()); } @Override public void warn(Marker marker, String format, Object... arguments) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.WARN, String.format(format, arguments)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.WARN, + new ParameterizedMessage(format, arguments).getFormattedMessage()); } @Override @@ -293,17 +369,26 @@ public void error(String msg) { @Override public void error(String format, Object arg) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.ERROR, String.format(format, arg)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.ERROR, + new ParameterizedMessage(format, arg).getFormattedMessage()); } @Override public void error(String format, Object arg1, Object arg2) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.ERROR, String.format(format, arg1, arg2)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.ERROR, + new ParameterizedMessage(format, arg1, arg2).getFormattedMessage()); } @Override public void error(String format, Object... arguments) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.ERROR, String.format(format, arguments)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.ERROR, + new ParameterizedMessage(format, arguments).getFormattedMessage()); } @Override @@ -324,17 +409,26 @@ public void error(Marker marker, String msg) { @Override public void error(Marker marker, String format, Object arg) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.ERROR, String.format(format, arg)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.ERROR, + new ParameterizedMessage(format, arg).getFormattedMessage()); } @Override public void error(Marker marker, String format, Object arg1, Object arg2) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.ERROR, String.format(format, arg1, arg2)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.ERROR, + new ParameterizedMessage(format, arg1, arg2).getFormattedMessage()); } @Override public void error(Marker marker, String format, Object... arguments) { - TracingSlf4jImpl.event(name, TracingSlf4jImpl.ERROR, String.format(format, arguments)); + TracingSlf4jImpl.event( + name, + TracingSlf4jImpl.ERROR, + new ParameterizedMessage(format, arguments).getFormattedMessage()); } @Override diff --git a/src/utils/runtime/src/logger.rs b/src/utils/runtime/src/logger.rs index e8abb0aef65e..8dde42ce783f 100644 --- a/src/utils/runtime/src/logger.rs +++ b/src/utils/runtime/src/logger.rs @@ -158,6 +158,7 @@ pub fn init_risingwave_logger(settings: LoggerSettings) { // Other RisingWave crates like `stream` and `storage` will follow the default level. filter = filter .with_target("risingwave_sqlparser", Level::INFO) + .with_target("risingwave_connector_node", Level::INFO) .with_target("pgwire", Level::INFO) .with_target(PGWIRE_QUERY_LOG, Level::OFF) // debug-purposed events are disabled unless `RUST_LOG` overrides