Skip to content

Commit

Permalink
Merge pull request #449 from dmlloyd/legacy-handlers
Browse files Browse the repository at this point in the history
Cater to legacy handlers
  • Loading branch information
jamezp authored Nov 28, 2023
2 parents 393579f + 3d97fc4 commit d852546
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/main/java/org/jboss/logmanager/LoggerNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.logging.Filter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;

import io.smallrye.common.constraint.Assert;
import io.smallrye.common.ref.PhantomReference;
Expand Down Expand Up @@ -428,10 +429,27 @@ void setUseParentHandlers(final boolean useParentHandlers) {
}
}

@SuppressWarnings("deprecation") // record#getFormattedMessage
void publish(final ExtLogRecord record) {
LogRecord oldRecord = null;
for (Handler handler : getHandlers())
try {
handler.publish(record);
if (handler instanceof ExtHandler || handler.getFormatter() instanceof ExtFormatter) {
handler.publish(record);
} else {
// old-style handlers generally don't know how to handle printf formatting
if (oldRecord == null) {
if (record.getFormatStyle() == ExtLogRecord.FormatStyle.PRINTF) {
// reformat it in a simple way, but only for legacy handler usage
oldRecord = new ExtLogRecord(record);
oldRecord.setMessage(record.getFormattedMessage());
oldRecord.setParameters(null);
} else {
oldRecord = record;
}
}
handler.publish(oldRecord);
}
} catch (VirtualMachineError e) {
throw e;
} catch (Throwable t) {
Expand Down

0 comments on commit d852546

Please sign in to comment.