You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "ppkarwasz (via GitHub)" <gi...@apache.org> on 2024/01/24 20:51:32 UTC

[PR] Remove instance of checks for async components (logging-log4j2)

ppkarwasz opened a new pull request, #2242:
URL: https://github.com/apache/logging-log4j2/pull/2242

   This PR removes all occurences of `instanceof Async*` that might prevent the separation of the async support.
   
   The removal requires a couple of new API methods and binary incompatible changes.
   
   


-- 
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: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Remove instance of checks for async components (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on code in PR #2242:
URL: https://github.com/apache/logging-log4j2/pull/2242#discussion_r1466576459


##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java:
##########
@@ -649,7 +649,7 @@ public boolean requiresLocation() {
         return false;
     }
 
-    private void logParent(final LogEvent event, final LoggerConfigPredicate predicate) {
+    private void logParent(final LogEvent event, final DispatchType predicate) {

Review Comment:
   In the corrected version I use `Predicate<LoggerConfig>`.



-- 
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: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Remove instance of checks for async components (logging-log4j2)

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on code in PR #2242:
URL: https://github.com/apache/logging-log4j2/pull/2242#discussion_r1466422551


##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java:
##########
@@ -614,15 +611,18 @@ public ReliabilityStrategy getReliabilityStrategy() {
      * Logs an event, bypassing filters.
      *
      * @param event     The log event.
-     * @param predicate predicate for which LoggerConfig instances to append to. A
-     *                  {@literal null} value is equivalent to a true predicate.
+     * @param dispatchType decides which logger configs should be used.
      */
-    protected void processLogEvent(final LogEvent event, final LoggerConfigPredicate predicate) {
+    protected void processLogEvent(final LogEvent event, final DispatchType dispatchType) {
         event.setIncludeLocation(isIncludeLocation());
-        if (predicate == null || predicate.allow(this)) {
+        if (hasDispatchType(dispatchType)) {
             callAppenders(event);
         }
-        logParent(event, predicate);
+        logParent(event, dispatchType);
+    }
+
+    protected boolean hasDispatchType(final DispatchType dispatchType) {
+        return dispatchType != DispatchType.ASYNCHRONOUS;

Review Comment:
   I am not able to follow the logic here. `hasDispatchType()` sounds like we will check if there are any dispatch types. Though we certainly don't do that. Plus, we only check if it is not async; again something I couldn't understand. Mind elaborating on what are you trying to do here? I was expecting something like `boolean dispatchTypeAllowed(DispatchType)`.
   
   Also, I am puzzled to see _async_ in `LoggerConfig`. `DispatchType` will still litter the `LoggerConfig` with `async` even if we split it into a separate module. Am I wrong? To avoid this, shouldn't `DispatchType` be a protected interface that integrators extend from instead?



##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java:
##########
@@ -649,7 +649,7 @@ public boolean requiresLocation() {
         return false;
     }
 
-    private void logParent(final LogEvent event, final LoggerConfigPredicate predicate) {
+    private void logParent(final LogEvent event, final DispatchType predicate) {

Review Comment:
   Could you rename `predicate` to `dispatchType`, please?



-- 
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: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Remove instance of checks for async components (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on code in PR #2242:
URL: https://github.com/apache/logging-log4j2/pull/2242#discussion_r1466575669


##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java:
##########
@@ -614,15 +611,18 @@ public ReliabilityStrategy getReliabilityStrategy() {
      * Logs an event, bypassing filters.
      *
      * @param event     The log event.
-     * @param predicate predicate for which LoggerConfig instances to append to. A
-     *                  {@literal null} value is equivalent to a true predicate.
+     * @param dispatchType decides which logger configs should be used.
      */
-    protected void processLogEvent(final LogEvent event, final LoggerConfigPredicate predicate) {
+    protected void processLogEvent(final LogEvent event, final DispatchType dispatchType) {
         event.setIncludeLocation(isIncludeLocation());
-        if (predicate == null || predicate.allow(this)) {
+        if (hasDispatchType(dispatchType)) {
             callAppenders(event);
         }
-        logParent(event, predicate);
+        logParent(event, dispatchType);
+    }
+
+    protected boolean hasDispatchType(final DispatchType dispatchType) {
+        return dispatchType != DispatchType.ASYNCHRONOUS;

Review Comment:
   I replaced `LoggerConfigPredicate` with `Predicate<LoggerConfig>`.
   All references to async in `log4j-core` should be gone.



-- 
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: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Remove instance of checks for async components (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz merged PR #2242:
URL: https://github.com/apache/logging-log4j2/pull/2242


-- 
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: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org