Skip to content

Commit

Permalink
Merge pull request #416 from jamezp/logger-overrides
Browse files Browse the repository at this point in the history
Override the new Supplier and logb logger methods.
  • Loading branch information
jamezp authored Jul 6, 2023
2 parents e94cfbb + 2e58a5e commit bac5742
Showing 1 changed file with 208 additions and 1 deletion.
209 changes: 208 additions & 1 deletion src/main/java/org/jboss/logmanager/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -528,6 +528,20 @@ public void severe(final String msg) {
logRaw(rec);
}

@Override
public void severe(final Supplier<String> 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;
Expand All @@ -542,6 +556,20 @@ public void warning(final String msg) {
logRaw(rec);
}

@Override
public void warning(final Supplier<String> 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;
Expand All @@ -556,6 +584,20 @@ public void info(final String msg) {
logRaw(rec);
}

@Override
public void info(final Supplier<String> 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;
Expand All @@ -570,6 +612,20 @@ public void config(final String msg) {
logRaw(rec);
}

@Override
public void config(final Supplier<String> 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;
Expand All @@ -584,6 +640,20 @@ public void fine(final String msg) {
logRaw(rec);
}

@Override
public void fine(final Supplier<String> 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;
Expand All @@ -598,6 +668,20 @@ public void finer(final String msg) {
logRaw(rec);
}

@Override
public void finer(final Supplier<String> 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;
Expand All @@ -612,6 +696,20 @@ public void finest(final String msg) {
logRaw(rec);
}

@Override
public void finest(final Supplier<String> 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;
Expand All @@ -626,6 +724,20 @@ public void log(final Level level, final String msg) {
logRaw(rec);
}

@Override
public void log(final Level level, final Supplier<String> 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;
Expand Down Expand Up @@ -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<String> 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;
Expand All @@ -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<String> 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) {
Expand Down Expand Up @@ -743,7 +887,26 @@ 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<String> 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} */
@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)
Expand All @@ -755,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)
Expand All @@ -766,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)
Expand All @@ -777,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)
Expand All @@ -787,6 +953,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

/**
Expand Down

0 comments on commit bac5742

Please sign in to comment.