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

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

commit 9fe638a628411b8b314fd860f689180cb7bb743b
Author: Matt Sicker <[email protected]>
AuthorDate: Sat Nov 5 13:22:09 2022 -0500

    Revert "Update LowLevelLogUtil to use replaceable functions"
    
    This reverts commit b177c3b1975716f47ae0772869fe7fc21c7bfa04.
---
 .../logging/log4j/util3/LowLevelLogUtil.java       | 49 ++++++++++++----------
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/util3/LowLevelLogUtil.java 
b/log4j-api/src/main/java/org/apache/logging/log4j/util3/LowLevelLogUtil.java
index 3a996c9668..7bb3f83d02 100644
--- 
a/log4j-api/src/main/java/org/apache/logging/log4j/util3/LowLevelLogUtil.java
+++ 
b/log4j-api/src/main/java/org/apache/logging/log4j/util3/LowLevelLogUtil.java
@@ -17,9 +17,10 @@
 
 package org.apache.logging.log4j.util3;
 
+import java.io.OutputStream;
 import java.io.PrintWriter;
-import java.util.function.BiConsumer;
-import java.util.function.Consumer;
+import java.io.Writer;
+import java.util.Objects;
 
 /**
  * PrintWriter-based logging utility for classes too low level to use {@link 
org.apache.logging.log4j.status.StatusLogger}.
@@ -29,25 +30,8 @@ import java.util.function.Consumer;
  * @since 2.6
  */
 public final class LowLevelLogUtil {
-    private static final PrintWriter STDERR = new PrintWriter(System.err, 
true);
-    private static Consumer<String> logErrorMessage = message -> 
STDERR.println("ERROR: " + message);
-    private static Consumer<Throwable> logException = exception -> 
exception.printStackTrace(STDERR);
-    private static BiConsumer<String, Throwable> logErrorWithException = 
(message, exception) -> {
-        log(message);
-        logException(exception);
-    };
 
-    public static void setLogErrorMessage(final Consumer<String> 
logErrorMessage) {
-        LowLevelLogUtil.logErrorMessage = logErrorMessage;
-    }
-
-    public static void setLogException(final Consumer<Throwable> logException) 
{
-        LowLevelLogUtil.logException = logException;
-    }
-
-    public static void setLogErrorWithException(final BiConsumer<String, 
Throwable> logErrorWithException) {
-        LowLevelLogUtil.logErrorWithException = logErrorWithException;
-    }
+    private static PrintWriter writer = new PrintWriter(System.err, true);
 
     /**
      * Logs the given message.
@@ -57,18 +41,37 @@ public final class LowLevelLogUtil {
      */
     public static void log(final String message) {
         if (message != null) {
-            logErrorMessage.accept(message);
+            writer.println(message);
         }
     }
 
     public static void logException(final Throwable exception) {
         if (exception != null) {
-            logException.accept(exception);
+            exception.printStackTrace(writer);
         }
     }
 
     public static void logException(final String message, final Throwable 
exception) {
-        logErrorWithException.accept(message, exception);
+        log(message);
+        logException(exception);
+    }
+
+    /**
+     * Sets the underlying OutputStream where exceptions are printed to.
+     *
+     * @param out the OutputStream to log to
+     */
+    public static void setOutputStream(final OutputStream out) {
+        LowLevelLogUtil.writer = new PrintWriter(Objects.requireNonNull(out), 
true);
+    }
+
+    /**
+     * Sets the underlying Writer where exceptions are printed to.
+     *
+     * @param writer the Writer to log to
+     */
+    public static void setWriter(final Writer writer) {
+        LowLevelLogUtil.writer = new 
PrintWriter(Objects.requireNonNull(writer), true);
     }
 
     private LowLevelLogUtil() {

Reply via email to