logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1481073 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
Date Fri, 10 May 2013 16:12:43 GMT
Author: rpopma
Date: Fri May 10 16:12:43 2013
New Revision: 1481073

URL: http://svn.apache.org/r1481073
Log:
findbugs fixes: be explicit about desired character encoding

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=1481073&r1=1481072&r2=1481073&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
Fri May 10 16:12:43 2013
@@ -30,7 +30,9 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Constructor;
+import java.nio.charset.Charset;
 
 /**
  * ConsoleAppender appends log events to <code>System.out</code> or
@@ -86,7 +88,7 @@ public final class ConsoleAppender<T ext
             return null;
         }
         if (layout == null) {
-            @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
+            @SuppressWarnings({"unchecked"})
             Layout<S> l = (Layout<S>)PatternLayout.createLayout(null, null, null,
null, null);
             layout = l;
         }
@@ -103,9 +105,15 @@ public final class ConsoleAppender<T ext
     }
 
     private static OutputStream getOutputStream(final boolean follow, final Target target)
{
-        final PrintStream printStream = target == Target.SYSTEM_OUT ?
-            follow ? new PrintStream(new SystemOutStream()) : System.out :
-            follow ? new PrintStream(new SystemErrStream()) : System.err;
+        final String enc = Charset.defaultCharset().name();
+        PrintStream printStream = null;
+        try {
+            printStream = target == Target.SYSTEM_OUT ?
+            follow ? new PrintStream(new SystemOutStream(), true, enc) : System.out :
+            follow ? new PrintStream(new SystemErrStream(), true, enc) : System.err;
+        } catch (UnsupportedEncodingException ex) { // should never happen
+            throw new IllegalStateException("Unsupported default encoding " + enc, ex);
+        }
         PropertiesUtil propsUtil = PropertiesUtil.getProperties();
         if (!propsUtil.getStringProperty("os.name").startsWith("Windows") ||
             propsUtil.getBooleanProperty("log4j.skipJansi")) {



Mime
View raw message