From 72c11778a5a1206d65d31a9d29d81d2c7f070b85 Mon Sep 17 00:00:00 2001 From: "James R. Perkins" Date: Thu, 6 Jul 2023 10:51:06 -0700 Subject: [PATCH 1/2] Override the new Supplier and logb logger methods. Signed-off-by: James R. Perkins --- .../java/org/jboss/logmanager/Logger.java | 205 +++++++++++++++++- 1 file changed, 204 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jboss/logmanager/Logger.java b/src/main/java/org/jboss/logmanager/Logger.java index 3290bb7a..d9186072 100644 --- a/src/main/java/org/jboss/logmanager/Logger.java +++ b/src/main/java/org/jboss/logmanager/Logger.java @@ -25,6 +25,7 @@ import java.util.Enumeration; import java.util.Locale; import java.util.ResourceBundle; +import java.util.function.Supplier; import java.util.logging.Filter; import java.util.logging.Handler; import java.util.logging.Level; @@ -97,7 +98,6 @@ public static Logger getLogger(final String name, final String bundleName) { super.setLevel(loggerNode.getLevel()); this.loggerNode = loggerNode; } - // Serialization protected final Object writeReplace() throws ObjectStreamException { @@ -528,6 +528,20 @@ public void severe(final String msg) { logRaw(rec); } + @Override + public void severe(final Supplier msgSupplier) { + Filter filter = null; + if (!(LogManager.PER_THREAD_LOG_FILTER && (filter = LogManager.getThreadLocalLogFilter()) != null) + && !loggerNode.isLoggableLevel(SEVERE_INT)) { + return; + } + final ExtLogRecord rec = new ExtLogRecord(Level.SEVERE, msgSupplier.get(), LOGGER_CLASS_NAME); + if (LogManager.PER_THREAD_LOG_FILTER && filter != null && !filter.isLoggable(rec)) { + return; + } + logRaw(rec); + } + /** {@inheritDoc} */ public void warning(final String msg) { Filter filter = null; @@ -542,6 +556,20 @@ public void warning(final String msg) { logRaw(rec); } + @Override + public void warning(final Supplier msgSupplier) { + Filter filter = null; + if (!(LogManager.PER_THREAD_LOG_FILTER && (filter = LogManager.getThreadLocalLogFilter()) != null) + && !loggerNode.isLoggableLevel(WARNING_INT)) { + return; + } + final ExtLogRecord rec = new ExtLogRecord(Level.WARNING, msgSupplier.get(), LOGGER_CLASS_NAME); + if (LogManager.PER_THREAD_LOG_FILTER && filter != null && !filter.isLoggable(rec)) { + return; + } + logRaw(rec); + } + /** {@inheritDoc} */ public void info(final String msg) { Filter filter = null; @@ -556,6 +584,20 @@ public void info(final String msg) { logRaw(rec); } + @Override + public void info(final Supplier msgSupplier) { + Filter filter = null; + if (!(LogManager.PER_THREAD_LOG_FILTER && (filter = LogManager.getThreadLocalLogFilter()) != null) + && !loggerNode.isLoggableLevel(INFO_INT)) { + return; + } + final ExtLogRecord rec = new ExtLogRecord(Level.INFO, msgSupplier.get(), LOGGER_CLASS_NAME); + if (LogManager.PER_THREAD_LOG_FILTER && filter != null && !filter.isLoggable(rec)) { + return; + } + logRaw(rec); + } + /** {@inheritDoc} */ public void config(final String msg) { Filter filter = null; @@ -570,6 +612,20 @@ public void config(final String msg) { logRaw(rec); } + @Override + public void config(final Supplier msgSupplier) { + Filter filter = null; + if (!(LogManager.PER_THREAD_LOG_FILTER && (filter = LogManager.getThreadLocalLogFilter()) != null) + && !loggerNode.isLoggableLevel(CONFIG_INT)) { + return; + } + final ExtLogRecord rec = new ExtLogRecord(Level.CONFIG, msgSupplier.get(), LOGGER_CLASS_NAME); + if (LogManager.PER_THREAD_LOG_FILTER && filter != null && !filter.isLoggable(rec)) { + return; + } + logRaw(rec); + } + /** {@inheritDoc} */ public void fine(final String msg) { Filter filter = null; @@ -584,6 +640,20 @@ public void fine(final String msg) { logRaw(rec); } + @Override + public void fine(final Supplier msgSupplier) { + Filter filter = null; + if (!(LogManager.PER_THREAD_LOG_FILTER && (filter = LogManager.getThreadLocalLogFilter()) != null) + && !loggerNode.isLoggableLevel(FINE_INT)) { + return; + } + final ExtLogRecord rec = new ExtLogRecord(Level.FINE, msgSupplier.get(), LOGGER_CLASS_NAME); + if (LogManager.PER_THREAD_LOG_FILTER && filter != null && !filter.isLoggable(rec)) { + return; + } + logRaw(rec); + } + /** {@inheritDoc} */ public void finer(final String msg) { Filter filter = null; @@ -598,6 +668,20 @@ public void finer(final String msg) { logRaw(rec); } + @Override + public void finer(final Supplier msgSupplier) { + Filter filter = null; + if (!(LogManager.PER_THREAD_LOG_FILTER && (filter = LogManager.getThreadLocalLogFilter()) != null) + && !loggerNode.isLoggableLevel(FINER_INT)) { + return; + } + final ExtLogRecord rec = new ExtLogRecord(Level.FINER, msgSupplier.get(), LOGGER_CLASS_NAME); + if (LogManager.PER_THREAD_LOG_FILTER && filter != null && !filter.isLoggable(rec)) { + return; + } + logRaw(rec); + } + /** {@inheritDoc} */ public void finest(final String msg) { Filter filter = null; @@ -612,6 +696,20 @@ public void finest(final String msg) { logRaw(rec); } + @Override + public void finest(final Supplier msgSupplier) { + Filter filter = null; + if (!(LogManager.PER_THREAD_LOG_FILTER && (filter = LogManager.getThreadLocalLogFilter()) != null) + && !loggerNode.isLoggableLevel(FINEST_INT)) { + return; + } + final ExtLogRecord rec = new ExtLogRecord(Level.FINEST, msgSupplier.get(), LOGGER_CLASS_NAME); + if (LogManager.PER_THREAD_LOG_FILTER && filter != null && !filter.isLoggable(rec)) { + return; + } + logRaw(rec); + } + /** {@inheritDoc} */ public void log(final Level level, final String msg) { Filter filter = null; @@ -626,6 +724,20 @@ public void log(final Level level, final String msg) { logRaw(rec); } + @Override + public void log(final Level level, final Supplier msgSupplier) { + Filter filter = null; + if (!(LogManager.PER_THREAD_LOG_FILTER && (filter = LogManager.getThreadLocalLogFilter()) != null) + && !loggerNode.isLoggableLevel(level.intValue())) { + return; + } + final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), LOGGER_CLASS_NAME); + if (LogManager.PER_THREAD_LOG_FILTER && filter != null && !filter.isLoggable(rec)) { + return; + } + logRaw(rec); + } + /** {@inheritDoc} */ public void log(final Level level, final String msg, final Object param1) { Filter filter = null; @@ -672,6 +784,21 @@ public void log(final Level level, final String msg, final Throwable thrown) { logRaw(rec); } + @Override + public void log(final Level level, final Throwable thrown, final Supplier msgSupplier) { + Filter filter = null; + if (!(LogManager.PER_THREAD_LOG_FILTER && (filter = LogManager.getThreadLocalLogFilter()) != null) + && !loggerNode.isLoggableLevel(level.intValue())) { + return; + } + final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), LOGGER_CLASS_NAME); + rec.setThrown(thrown); + if (LogManager.PER_THREAD_LOG_FILTER && filter != null && !filter.isLoggable(rec)) { + return; + } + logRaw(rec); + } + /** {@inheritDoc} */ public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg) { Filter filter = null; @@ -688,6 +815,23 @@ public void logp(final Level level, final String sourceClass, final String sourc logRaw(rec); } + @Override + public void logp(final Level level, final String sourceClass, final String sourceMethod, + final Supplier msgSupplier) { + Filter filter = null; + if (!(LogManager.PER_THREAD_LOG_FILTER && (filter = LogManager.getThreadLocalLogFilter()) != null) + && !loggerNode.isLoggableLevel(level.intValue())) { + return; + } + final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), LOGGER_CLASS_NAME); + rec.setSourceClassName(sourceClass); + rec.setSourceMethodName(sourceMethod); + if (LogManager.PER_THREAD_LOG_FILTER && filter != null && !filter.isLoggable(rec)) { + return; + } + logRaw(rec); + } + /** {@inheritDoc} */ public void logp(final Level level, final String sourceClass, final String sourceMethod, final String msg, final Object param1) { @@ -743,6 +887,24 @@ public void logp(final Level level, final String sourceClass, final String sourc logRaw(rec); } + @Override + public void logp(final Level level, final String sourceClass, final String sourceMethod, final Throwable thrown, + final Supplier msgSupplier) { + Filter filter = null; + if (!(LogManager.PER_THREAD_LOG_FILTER && (filter = LogManager.getThreadLocalLogFilter()) != null) + && !loggerNode.isLoggableLevel(level.intValue())) { + return; + } + final ExtLogRecord rec = new ExtLogRecord(level, msgSupplier.get(), LOGGER_CLASS_NAME); + rec.setSourceClassName(sourceClass); + rec.setSourceMethodName(sourceMethod); + rec.setThrown(thrown); + if (LogManager.PER_THREAD_LOG_FILTER && filter != null && !filter.isLoggable(rec)) { + return; + } + logRaw(rec); + } + /** {@inheritDoc} */ public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName, final String msg) { @@ -787,6 +949,47 @@ public void logrb(final Level level, final String sourceClass, final String sour super.logrb(level, sourceClass, sourceMethod, bundleName, msg, thrown); } + @Override + public void logrb(final Level level, final String sourceClass, final String sourceMethod, final ResourceBundle bundle, + final String msg, final Object... params) { + if (!(LogManager.PER_THREAD_LOG_FILTER && LogManager.getThreadLocalLogFilter() != null) + && !loggerNode.isLoggableLevel(level.intValue())) { + return; + } + // No local check is needed here as this will delegate to log(LogRecord) + super.logrb(level, sourceClass, sourceMethod, bundle, msg, params); + } + + @Override + public void logrb(final Level level, final ResourceBundle bundle, final String msg, final Object... params) { + if (!(LogManager.PER_THREAD_LOG_FILTER && LogManager.getThreadLocalLogFilter() != null) + && !loggerNode.isLoggableLevel(level.intValue())) { + return; + } + // No local check is needed here as this will delegate to log(LogRecord) + super.logrb(level, bundle, msg, params); + } + + @Override + public void logrb(final Level level, final String sourceClass, final String sourceMethod, final ResourceBundle bundle, + final String msg, final Throwable thrown) { + if (!(LogManager.PER_THREAD_LOG_FILTER && LogManager.getThreadLocalLogFilter() != null) + && !loggerNode.isLoggableLevel(level.intValue())) { + return; + } + // No local check is needed here as this will delegate to log(LogRecord) + super.logrb(level, sourceClass, sourceMethod, bundle, msg, thrown); + } + + @Override + public void logrb(final Level level, final ResourceBundle bundle, final String msg, final Throwable thrown) { + if (!(LogManager.PER_THREAD_LOG_FILTER && LogManager.getThreadLocalLogFilter() != null) + && !loggerNode.isLoggableLevel(level.intValue())) { + return; + } + // No local check is needed here as this will delegate to log(LogRecord) + super.logrb(level, bundle, msg, thrown); + } // alternate SPI hooks /** From 2e58a5e3d09c0dc06126d2c1b335ac9747672b10 Mon Sep 17 00:00:00 2001 From: "James R. Perkins" Date: Thu, 6 Jul 2023 11:06:25 -0700 Subject: [PATCH 2/2] Deprecate the methods deprecated in the super class. Signed-off-by: James R. Perkins --- src/main/java/org/jboss/logmanager/Logger.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/jboss/logmanager/Logger.java b/src/main/java/org/jboss/logmanager/Logger.java index d9186072..6863fe55 100644 --- a/src/main/java/org/jboss/logmanager/Logger.java +++ b/src/main/java/org/jboss/logmanager/Logger.java @@ -906,6 +906,7 @@ public void logp(final Level level, final String sourceClass, final String sourc } /** {@inheritDoc} */ + @Deprecated(since = "3.0", forRemoval = true) public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName, final String msg) { if (!(LogManager.PER_THREAD_LOG_FILTER && LogManager.getThreadLocalLogFilter() != null) @@ -917,6 +918,7 @@ public void logrb(final Level level, final String sourceClass, final String sour } /** {@inheritDoc} */ + @Deprecated(since = "3.0", forRemoval = true) public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName, final String msg, final Object param1) { if (!(LogManager.PER_THREAD_LOG_FILTER && LogManager.getThreadLocalLogFilter() != null) @@ -928,6 +930,7 @@ public void logrb(final Level level, final String sourceClass, final String sour } /** {@inheritDoc} */ + @Deprecated(since = "3.0", forRemoval = true) public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName, final String msg, final Object[] params) { if (!(LogManager.PER_THREAD_LOG_FILTER && LogManager.getThreadLocalLogFilter() != null) @@ -939,6 +942,7 @@ public void logrb(final Level level, final String sourceClass, final String sour } /** {@inheritDoc} */ + @Deprecated(since = "3.0", forRemoval = true) public void logrb(final Level level, final String sourceClass, final String sourceMethod, final String bundleName, final String msg, final Throwable thrown) { if (!(LogManager.PER_THREAD_LOG_FILTER && LogManager.getThreadLocalLogFilter() != null)