Skip to content

Commit

Permalink
Merge pull request #9 from jamezp/issue7
Browse files Browse the repository at this point in the history
[#7] Pass the format parameters to the log record. Also use the NO_FO…
  • Loading branch information
jamezp committed Oct 12, 2020
2 parents 18431a3 + df25510 commit 64f8f14
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/main/java/org/slf4j/impl/Slf4jLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void log(final Marker marker, final String fqcn, final int levelVal, fina
default: level = org.jboss.logmanager.Level.DEBUG; break;
}
if (logger.isLoggable(level)) {
log(level, fqcn, message, t);
log(level, fqcn, message, t, argArray);
}
}

Expand All @@ -87,7 +87,7 @@ public void trace(final String format, final Object arg) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.format(format, arg);
log(org.jboss.logmanager.Level.TRACE, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.TRACE, formattingTuple.getMessage(), formattingTuple.getThrowable(), arg);
}

@Override
Expand All @@ -96,7 +96,7 @@ public void trace(final String format, final Object arg1, final Object arg2) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.format(format, arg1, arg2);
log(org.jboss.logmanager.Level.TRACE, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.TRACE, formattingTuple.getMessage(), formattingTuple.getThrowable(), arg1, arg2);
}

@Override
Expand All @@ -105,7 +105,7 @@ public void trace(final String format, final Object... arguments) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.arrayFormat(format, arguments);
log(org.jboss.logmanager.Level.TRACE, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.TRACE, formattingTuple.getMessage(), formattingTuple.getThrowable(), arguments);
}

@Override
Expand Down Expand Up @@ -135,7 +135,7 @@ public void debug(final String format, final Object arg) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.format(format, arg);
log(org.jboss.logmanager.Level.DEBUG, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.DEBUG, formattingTuple.getMessage(), formattingTuple.getThrowable(), arg);
}

@Override
Expand All @@ -144,7 +144,7 @@ public void debug(final String format, final Object arg1, final Object arg2) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.format(format, arg1, arg2);
log(org.jboss.logmanager.Level.DEBUG, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.DEBUG, formattingTuple.getMessage(), formattingTuple.getThrowable(), arg1, arg2);
}

@Override
Expand All @@ -153,7 +153,7 @@ public void debug(final String format, final Object... arguments) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.arrayFormat(format, arguments);
log(org.jboss.logmanager.Level.DEBUG, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.DEBUG, formattingTuple.getMessage(), formattingTuple.getThrowable(), arguments);
}

@Override
Expand Down Expand Up @@ -183,7 +183,7 @@ public void info(final String format, final Object arg) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.format(format, arg);
log(org.jboss.logmanager.Level.INFO, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.INFO, formattingTuple.getMessage(), formattingTuple.getThrowable(), arg);
}

@Override
Expand All @@ -192,7 +192,7 @@ public void info(final String format, final Object arg1, final Object arg2) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.format(format, arg1, arg2);
log(org.jboss.logmanager.Level.INFO, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.INFO, formattingTuple.getMessage(), formattingTuple.getThrowable(), arg1, arg2);
}

@Override
Expand All @@ -201,7 +201,7 @@ public void info(final String format, final Object... arguments) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.arrayFormat(format, arguments);
log(org.jboss.logmanager.Level.INFO, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.INFO, formattingTuple.getMessage(), formattingTuple.getThrowable(), arguments);
}

@Override
Expand Down Expand Up @@ -231,7 +231,7 @@ public void warn(final String format, final Object arg) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.format(format, arg);
log(org.jboss.logmanager.Level.WARN, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.WARN, formattingTuple.getMessage(), formattingTuple.getThrowable(), arg);
}

@Override
Expand All @@ -240,7 +240,7 @@ public void warn(final String format, final Object... arguments) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.arrayFormat(format, arguments);
log(org.jboss.logmanager.Level.WARN, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.WARN, formattingTuple.getMessage(), formattingTuple.getThrowable(), arguments);
}

@Override
Expand All @@ -249,7 +249,7 @@ public void warn(final String format, final Object arg1, final Object arg2) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.format(format, arg1, arg2);
log(org.jboss.logmanager.Level.WARN, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.WARN, formattingTuple.getMessage(), formattingTuple.getThrowable(), arg1, arg2);
}

@Override
Expand Down Expand Up @@ -279,7 +279,7 @@ public void error(final String format, final Object arg) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.format(format, arg);
log(org.jboss.logmanager.Level.ERROR, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.ERROR, formattingTuple.getMessage(), formattingTuple.getThrowable(), arg);
}

@Override
Expand All @@ -288,7 +288,7 @@ public void error(final String format, final Object arg1, final Object arg2) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.format(format, arg1, arg2);
log(org.jboss.logmanager.Level.ERROR, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.ERROR, formattingTuple.getMessage(), formattingTuple.getThrowable(), arg1, arg2);
}

@Override
Expand All @@ -297,7 +297,7 @@ public void error(final String format, final Object... arguments) {
return;
}
final FormattingTuple formattingTuple = MessageFormatter.arrayFormat(format, arguments);
log(org.jboss.logmanager.Level.ERROR, formattingTuple.getMessage(), formattingTuple.getThrowable());
log(org.jboss.logmanager.Level.ERROR, formattingTuple.getMessage(), formattingTuple.getThrowable(), arguments);
}

@Override
Expand All @@ -314,12 +314,19 @@ protected Slf4jLogger readResolve() throws ObjectStreamException {
}

private void log(final java.util.logging.Level level, final String message, final Throwable t) {
log(level, LOGGER_CLASS_NAME, message, t);
final ExtLogRecord rec = new ExtLogRecord(level, message, LOGGER_CLASS_NAME);
rec.setThrown(t);
logger.logRaw(rec);
}

private void log(final java.util.logging.Level level, final String message, final Throwable t, final Object... params) {
log(level, LOGGER_CLASS_NAME, message, t, params);
}

private void log(final java.util.logging.Level level, final String fqcn, final String message, final Throwable t) {
final ExtLogRecord rec = new ExtLogRecord(level, message, fqcn);
private void log(final java.util.logging.Level level, final String fqcn, final String message, final Throwable t, final Object[] params) {
final ExtLogRecord rec = new ExtLogRecord(level, message, ExtLogRecord.FormatStyle.NO_FORMAT, fqcn);
rec.setThrown(t);
rec.setParameters(params);
logger.logRaw(rec);
}
}

0 comments on commit 64f8f14

Please sign in to comment.