logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1394290 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
Date Thu, 04 Oct 2012 21:56:09 GMT
Author: ggregory
Date: Thu Oct  4 21:56:09 2012
New Revision: 1394290

URL: http://svn.apache.org/viewvc?rev=1394290&view=rev
Log:
Refactor duplicated code in getOutputStream(Target).

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java?rev=1394290&r1=1394289&r2=1394290&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
Thu Oct  4 21:56:09 2012
@@ -26,6 +26,7 @@ import org.apache.logging.log4j.core.hel
 import org.apache.logging.log4j.core.layout.PatternLayout;
 
 import java.io.OutputStream;
+import java.io.PrintStream;
 import java.lang.reflect.Constructor;
 
 /**
@@ -93,14 +94,15 @@ public final class ConsoleAppender exten
     }
 
     private static OutputStream getOutputStream(Target target) {
+        final PrintStream printStream = target == Target.SYSTEM_OUT ? System.out : System.err;
         if (!System.getProperty("os.name").startsWith("Windows")) {
-            return target == Target.SYSTEM_OUT ? System.out : System.err;
+            return printStream;
         } else {
             try {
                 ClassLoader loader = Loader.getClassLoader();
                 Class clazz = loader.loadClass("org.fusesource.jansi.WindowsAnsiOutputStream");
                 Constructor constructor = clazz.getConstructor(OutputStream.class);
-                return (OutputStream) constructor.newInstance(target == Target.SYSTEM_OUT
? System.out : System.err);
+                return (OutputStream) constructor.newInstance(printStream);
             } catch (ClassNotFoundException cnfe) {
                 LOGGER.debug("Jansi is not installed");
             } catch (NoSuchMethodException nsme) {
@@ -108,7 +110,7 @@ public final class ConsoleAppender exten
             } catch (Exception ex) {
                 LOGGER.warn("Unable to instantiate WindowsAnsiOutputStream");
             }
-            return target == Target.SYSTEM_OUT ? System.out : System.err;
+            return printStream;
         }
     }
 



Mime
View raw message