logging-log4j2 icon indicating copy to clipboard operation
logging-log4j2 copied to clipboard

Change access of AsyncLogger constructor back to public

Open sundaybluesky opened this issue 7 months ago • 4 comments

AsyncLogger constructor access changed from public to package-private at 2.24.3 code change - https://github.com/apache/logging-log4j2/pull/3263 blocked our CustomLogger instances initialization.

We have a requirement to introduce extra enablement checks in AsyncLogger isEnabled methods to control print out logs or not. Actually AsyncLogger is not extension friendly due to internal referenced AsyncLoggerDisruptor.class constructor is private. Before 2.24.3, we've created CustomLogger with the same package org.apache.logging.log4j.core.async as AsyncLogger and use reflection to initialize CustomLogger instances and it is working 7+ years.

Code sample,

package org.apache.logging.log4j.core.async;

public class CustomLogger extends AsyncLogger {

        @Override
	public boolean isEnabled(final Level level, final Marker marker, final String message) {
           if (isCustomEnablementOn) {
               return true;
           }
           return super.isEnabled(level, marker, message);
        }
}

Asks Change AsyncLogger constructor access back to public and consider make AsyncLogger more extensible, user can extend, override AsyncLogger and create subclass of AsyncLogger instance directly, no limitation on private AsyncLoggerDisruptor.class or others internal referenced classes access.

sundaybluesky avatar Mar 11 '25 08:03 sundaybluesky