Skip to content

Commit

Permalink
Merge pull request #471 from jamezp/LOGMGR-352
Browse files Browse the repository at this point in the history
[LOGMGR-351] Remove the deprecated per-deployment logging options.
  • Loading branch information
jamezp authored Apr 24, 2024
2 parents a248939 + af8d4f4 commit 5f444f8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 268 deletions.
41 changes: 0 additions & 41 deletions src/main/java/org/jboss/logmanager/LogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.logging.Filter;

import org.jboss.logmanager.configuration.PropertyLogContextConfigurator;

Expand All @@ -43,24 +42,14 @@
*/
public final class LogManager extends java.util.logging.LogManager {

public static final String PER_THREAD_LOG_FILTER_KEY = "org.jboss.logmanager.useThreadLocalFilter";
static final boolean PER_THREAD_LOG_FILTER;

static {
if (System.getSecurityManager() == null) {
try {
// Ensure the StandardOutputStreams are initialized early to capture the current System.out and System.err.
Class.forName(StandardOutputStreams.class.getName());
} catch (ClassNotFoundException ignore) {
}
PER_THREAD_LOG_FILTER = Boolean.getBoolean(PER_THREAD_LOG_FILTER_KEY);
} else {
PER_THREAD_LOG_FILTER = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
return Boolean.getBoolean(PER_THREAD_LOG_FILTER_KEY);
}
});

AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
Expand All @@ -76,10 +65,6 @@ public Object run() {
}
}

private static class LocalFilterHolder {
static final ThreadLocal<Filter> LOCAL_FILTER = new ThreadLocal<>();
}

/**
* Construct a new logmanager instance. Attempts to plug a known memory leak in {@link java.util.logging.Level} as
* well.
Expand Down Expand Up @@ -237,30 +222,4 @@ public boolean addLogger(java.util.logging.Logger logger) {
public Logger getLogger(String name) {
return LogContext.getLogContext().getLogger(name);
}

/**
* Returns the currently set filter for this thread or {@code null} if one has not been set.
* <p>
* If the {@link #PER_THREAD_LOG_FILTER_KEY} is not set to {@code true} then {@code null} will always be returned.
* </p>
*
* @return the filter set for the thread or {@code null} if no level was set
*/
public static Filter getThreadLocalLogFilter() {
return PER_THREAD_LOG_FILTER ? LocalFilterHolder.LOCAL_FILTER.get() : null;
}

/**
* Sets the filter on the thread for all loggers.
* <p>
* This feature only works if the {@link #PER_THREAD_LOG_FILTER} was set to {@code true}
* </p>
*
* @param filter the filter to set for all loggers on this thread
*/
public static void setThreadLocalLogLevel(final Filter filter) {
if (PER_THREAD_LOG_FILTER) {
LocalFilterHolder.LOCAL_FILTER.set(filter);
}
}
}
Loading

0 comments on commit 5f444f8

Please sign in to comment.