Skip to content

Commit

Permalink
fix(connector): use log4j's string interpolation (#14206)
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao authored Dec 26, 2023
1 parent 5a312a2 commit a8d0541
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 31 deletions.
4 changes: 4 additions & 0 deletions java/connector-node/tracing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/utils/runtime/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a8d0541

Please sign in to comment.