ramanathan1504 commented on code in PR #4465:
URL: https://github.com/apache/logging-log4j2/pull/4465#discussion_r4505312165


##########
log4j-jul/src/main/java/org/apache/logging/log4j/jul/ApiLogger.java:
##########
@@ -125,22 +131,34 @@ protected void doSetLevel(final Level newLevel) throws 
SecurityException {
 
     @Override
     public void setUseParentHandlers(boolean useParentHandlers) {
-        LOGGER.warn(MUTATOR_DISABLED, "setUseParentHandlers", 
useParentHandlers);
+        warnMutatorAccess("setUseParentHandlers", useParentHandlers);
         super.setUseParentHandlers(useParentHandlers);
     }
 
     @Override
     public void addHandler(Handler handler) throws SecurityException {
-        LOGGER.warn(MUTATOR_DISABLED, "addHandler", handler);
+        warnMutatorAccess("addHandler", handler);
         super.addHandler(handler);
     }
 
     @Override
     public void removeHandler(Handler handler) throws SecurityException {
-        LOGGER.warn(MUTATOR_DISABLED, "removeHandler", handler);
+        warnMutatorAccess("removeHandler", handler);
         super.removeHandler(handler);
     }
 
+    private static void warnMutatorAccess(final String method, final Object 
argument) {
+        final String mode = 
PropertiesUtil.getProperties().getStringProperty("log4j2.julMutatorAccess", 
"warn-once");
+        if ("ignore".equalsIgnoreCase(mode) || !LOGGER.isWarnEnabled()) {
+            return;
+        }
+        if (!"warn".equalsIgnoreCase(mode) && 
!MUTATOR_WARNING_REPORTED.compareAndSet(false, true)) {
+            return;
+        }
+        final StackTraceElement caller = StackLocatorUtil.calcLocation(FQCN);
+        LOGGER.warn(MUTATOR_DISABLED, method, argument, caller == null ? 
"unknown" : caller.getClassName());
+    }
+
     @Override
     public void setResourceBundle(ResourceBundle bundle) {

Review Comment:
   `setResourceBundle` still warns on every call, and 
`log4j2.julMutatorAccess=ignore` does not silence it. Should it go through 
`warnMutatorAccess` too?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to