You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ck...@apache.org on 2021/09/13 18:50:50 UTC

[logging-log4j2] 02/02: Minor cleanup in AbstractLogger

This is an automated email from the ASF dual-hosted git repository.

ckozak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 1d56dac20d0827300a49a8cd9f0324185451757e
Author: Carter Kozak <ck...@apache.org>
AuthorDate: Fri Sep 10 16:51:02 2021 -0400

    Minor cleanup in AbstractLogger
    
    Static threadlocal field `recursionDepthHolder` is final
    Deduplication in `decrementRecursionDepth()`
    handleLogMessageException uses interpolation to avoid overhead
    when warnings are disabled
---
 .../org/apache/logging/log4j/spi/AbstractLogger.java   | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java b/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
index 78a4261..c16af58 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
@@ -2106,11 +2106,11 @@ public abstract class AbstractLogger implements ExtendedLogger, Serializable {
     private static void incrementRecursionDepth() {
         getRecursionDepthHolder()[0]++;
     }
+
     private static void decrementRecursionDepth() {
-        final int[] depth = getRecursionDepthHolder();
-        depth[0]--;
-        if (depth[0] < 0) {
-            throw new IllegalStateException("Recursion depth became negative: " + depth[0]);
+        int newDepth = --getRecursionDepthHolder()[0];
+        if (newDepth < 0) {
+            throw new IllegalStateException("Recursion depth became negative: " + newDepth);
         }
     }
 
@@ -2150,12 +2150,16 @@ public abstract class AbstractLogger implements ExtendedLogger, Serializable {
 
     // LOG4J2-1990 Log4j2 suppresses all exceptions that occur once application called the logger
     // TODO Configuration setting to propagate exceptions back to the caller *if requested*
-    private void handleLogMessageException(final Exception exception, final String fqcn, final Message msg) {
+    private void handleLogMessageException(final Exception exception, final String fqcn, final Message message) {
         if (exception instanceof LoggingException) {
             throw (LoggingException) exception;
         }
-        StatusLogger.getLogger().warn("{} caught {} logging {}: {}", fqcn, exception.getClass().getName(),
-                msg.getClass().getSimpleName(), msg.getFormat(), exception);
+        StatusLogger.getLogger().warn("{} caught {} logging {}: {}",
+                fqcn,
+                exception.getClass().getName(),
+                message.getClass().getSimpleName(),
+                message.getFormat(),
+                exception);
     }
 
     @Override