Support Logger#log(Level,String,Object)

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2013-10-28 11:37:46 -05:00
parent 874bf4ef4c
commit 6159f5cd3c
2 changed files with 25 additions and 1 deletions

View File

@ -80,6 +80,30 @@ public class Logger {
log(level, Method.getCaller(), message, exception);
}
public void log(Level level, String message, Object param) {
log(level, Method.getCaller(), replaceParameters(message, param), null);
}
private static String replaceParameters(String message, Object... params) {
StringBuilder builder = new StringBuilder();
int offset = 0;
for (int i = 0; i < params.length; ++i) {
int curly = message.indexOf("{}", offset);
if (curly < 0) {
break;
}
if (curly > offset) {
builder.append(message, offset, curly);
}
offset = curly + 2;
builder.append(params[i]);
}
if (message.length() > offset) {
builder.append(message, offset, message.length());
}
return builder.toString();
}
public void logp(Level level, String sourceClass, String sourceMethod, String msg) {
if (!isLoggable(level)) {
return;

View File

@ -66,7 +66,7 @@ public class Logging {
public void run() {
log.info("Started run");
a();
log.info("Ended run");
log.log(Level.INFO, "Ended {}!", "run");
}
private void a() {