Skip to content

Commit

Permalink
Merge pull request #493 from dmlloyd/no-format
Browse files Browse the repository at this point in the history
Use `NO_FORMAT` when using parameterless log methods
  • Loading branch information
jamezp authored Nov 19, 2024
2 parents 8334439 + 80b88fb commit afcc558
Showing 1 changed file with 49 additions and 33 deletions.
82 changes: 49 additions & 33 deletions src/main/java/org/jboss/logmanager/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

package org.jboss.logmanager;

import static org.jboss.logmanager.ExtLogRecord.FormatStyle.MESSAGE_FORMAT;
import static org.jboss.logmanager.ExtLogRecord.FormatStyle.NO_FORMAT;

import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.Arrays;
Expand Down Expand Up @@ -407,7 +410,7 @@ public void entering(final String sourceClass, final String sourceMethod) {
if (!loggerNode.isLoggableLevel(FINER_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, "ENTRY", LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, "ENTRY", NO_FORMAT, LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
logRaw(rec);
Expand All @@ -431,11 +434,16 @@ public void entering(final String sourceClass, final String sourceMethod, final
return;
}
final StringBuilder builder = new StringBuilder("ENTRY");
if (params != null)
ExtLogRecord.FormatStyle style;
if (params != null && params.length > 0) {
for (int i = 0; i < params.length; i++) {
builder.append(" {").append(i).append('}');
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, builder.toString(), LOGGER_CLASS_NAME);
style = MESSAGE_FORMAT;
} else {
style = NO_FORMAT;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, builder.toString(), style, LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
if (params != null)
Expand All @@ -448,7 +456,7 @@ public void exiting(final String sourceClass, final String sourceMethod) {
if (!loggerNode.isLoggableLevel(FINER_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, "RETURN", LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, "RETURN", NO_FORMAT, LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
logRaw(rec);
Expand All @@ -471,7 +479,7 @@ public void throwing(final String sourceClass, final String sourceMethod, final
if (!loggerNode.isLoggableLevel(FINER_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, "THROW", LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, "THROW", NO_FORMAT, LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setThrown(thrown);
Expand All @@ -483,7 +491,7 @@ public void severe(final String msg) {
if (!loggerNode.isLoggableLevel(SEVERE_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.SEVERE, msg, LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.SEVERE, msg, NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -492,7 +500,7 @@ public void severe(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(SEVERE_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.SEVERE, msgSupplier.get(), LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.SEVERE, msgSupplier.get(), NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -501,7 +509,7 @@ public void warning(final String msg) {
if (!loggerNode.isLoggableLevel(WARNING_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.WARNING, msg, LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.WARNING, msg, NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -510,7 +518,7 @@ public void warning(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(WARNING_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.WARNING, msgSupplier.get(), LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.WARNING, msgSupplier.get(), NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -519,7 +527,7 @@ public void info(final String msg) {
if (!loggerNode.isLoggableLevel(INFO_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.INFO, msg, LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.INFO, msg, NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -528,7 +536,7 @@ public void info(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(INFO_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.INFO, msgSupplier.get(), LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.INFO, msgSupplier.get(), NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -537,7 +545,7 @@ public void config(final String msg) {
if (!loggerNode.isLoggableLevel(CONFIG_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.CONFIG, msg, LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.CONFIG, msg, NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -546,7 +554,7 @@ public void config(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(CONFIG_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.CONFIG, msgSupplier.get(), LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.CONFIG, msgSupplier.get(), NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -555,7 +563,7 @@ public void fine(final String msg) {
if (!loggerNode.isLoggableLevel(FINE_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINE, msg, LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.FINE, msg, NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -564,7 +572,7 @@ public void fine(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(FINE_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINE, msgSupplier.get(), LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.FINE, msgSupplier.get(), NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -573,7 +581,7 @@ public void finer(final String msg) {
if (!loggerNode.isLoggableLevel(FINER_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, msg, LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, msg, NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -582,7 +590,7 @@ public void finer(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(FINER_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, msgSupplier.get(), LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, msgSupplier.get(), NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -591,7 +599,7 @@ public void finest(final String msg) {
if (!loggerNode.isLoggableLevel(FINEST_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINEST, msg, LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.FINEST, msg, NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -600,7 +608,7 @@ public void finest(final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(FINEST_INT)) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(Level.FINEST, msgSupplier.get(), LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(Level.FINEST, msgSupplier.get(), NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -609,7 +617,7 @@ public void log(final Level level, final String msg) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(level, msg, NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -618,7 +626,7 @@ public void log(final Level level, final Supplier<String> msgSupplier) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), NO_FORMAT, LOGGER_CLASS_NAME);
logRaw(rec);
}

Expand All @@ -637,9 +645,13 @@ public void log(final Level level, final String msg, final Object[] params) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
if (params != null)
final ExtLogRecord rec;
if (params != null && params.length > 0) {
rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
rec.setParameters(params);
} else {
rec = new ExtLogRecord(level, msg, NO_FORMAT, LOGGER_CLASS_NAME);
}
logRaw(rec);
}

Expand All @@ -648,7 +660,7 @@ public void log(final Level level, final String msg, final Throwable thrown) {
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(level, msg, NO_FORMAT, LOGGER_CLASS_NAME);
rec.setThrown(thrown);
logRaw(rec);
}
Expand All @@ -658,7 +670,7 @@ public void log(final Level level, final Throwable thrown, final Supplier<String
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), NO_FORMAT, LOGGER_CLASS_NAME);
rec.setThrown(thrown);
logRaw(rec);
}
Expand All @@ -668,7 +680,7 @@ public void logp(final Level level, final String sourceClass, final String sourc
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(level, msg, NO_FORMAT, LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
logRaw(rec);
Expand All @@ -680,7 +692,7 @@ public void logp(final Level level, final String sourceClass, final String sourc
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), NO_FORMAT, LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
logRaw(rec);
Expand All @@ -705,11 +717,15 @@ public void logp(final Level level, final String sourceClass, final String sourc
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
final ExtLogRecord rec;
if (params != null && params.length > 0) {
rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
rec.setParameters(params);
} else {
rec = new ExtLogRecord(level, msg, NO_FORMAT, LOGGER_CLASS_NAME);
}
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
if (params != null)
rec.setParameters(params);
logRaw(rec);
}

Expand All @@ -719,7 +735,7 @@ public void logp(final Level level, final String sourceClass, final String sourc
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(level, msg, NO_FORMAT, LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setThrown(thrown);
Expand All @@ -732,7 +748,7 @@ public void logp(final Level level, final String sourceClass, final String sourc
if (!loggerNode.isLoggableLevel(level.intValue())) {
return;
}
final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), LOGGER_CLASS_NAME);
final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), NO_FORMAT, LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setThrown(thrown);
Expand Down Expand Up @@ -877,7 +893,7 @@ public void log(final String fqcn, final Level level, final String message, fina
* @param t the throwable, if any
*/
public void log(final String fqcn, final Level level, final String message, final Throwable t) {
log(fqcn, level, message, ExtLogRecord.FormatStyle.MESSAGE_FORMAT, null, t);
log(fqcn, level, message, NO_FORMAT, null, t);
}

/**
Expand Down

0 comments on commit afcc558

Please sign in to comment.