From 1f7b169a13ca9c68894035d56ddbe0838025ead2 Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Wed, 29 Nov 2023 13:35:01 -0600 Subject: [PATCH] Cater to legacy sub-handlers Follow up on #449 to apply the same treatment to sub-handlers of a handler. --- .../java/org/jboss/logmanager/ExtHandler.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jboss/logmanager/ExtHandler.java b/src/main/java/org/jboss/logmanager/ExtHandler.java index 12ff31c8..264a658a 100644 --- a/src/main/java/org/jboss/logmanager/ExtHandler.java +++ b/src/main/java/org/jboss/logmanager/ExtHandler.java @@ -114,12 +114,29 @@ public void publish(final ExtLogRecord record) { * * @param record the log record to publish */ + @SuppressWarnings("deprecation") // record.getFormattedMessage() protected void publishToNestedHandlers(final ExtLogRecord record) { if (record != null) { + LogRecord oldRecord = null; for (Handler handler : getHandlers()) try { if (handler != null) { - 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 (Exception e) { reportError(handler, "Nested handler publication threw an exception", e, ErrorManager.WRITE_FAILURE);