commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1363177 - in /commons/proper/logging/trunk: RELEASE-NOTES.txt src/java/org/apache/commons/logging/LogFactory.java
Date Wed, 18 Jul 2012 23:47:49 GMT
Author: sebb
Date: Wed Jul 18 23:47:49 2012
New Revision: 1363177

URL: http://svn.apache.org/viewvc?rev=1363177&view=rev
Log:
LOGGING-148 - LogFactory.diagnosticPrefix and diagnosticsStream could be final

Modified:
    commons/proper/logging/trunk/RELEASE-NOTES.txt
    commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java

Modified: commons/proper/logging/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/logging/trunk/RELEASE-NOTES.txt?rev=1363177&r1=1363176&r2=1363177&view=diff
==============================================================================
--- commons/proper/logging/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/logging/trunk/RELEASE-NOTES.txt Wed Jul 18 23:47:49 2012
@@ -23,6 +23,7 @@ LOGGING-145 - LogFactoryImpl.setAttribut
 LOGGING-142 - Log4JLogger uses deprecated static members of Priority such as INFO
 LOGGING-128 - Static analysis suggests a number of potential improvements
 LOGGING-147 - SimpleLog.log - unsafe update of shortLogName
+LOGGING-148 - LogFactory.diagnosticPrefix and diagnosticsStream could be final
 
 $Id$
 

Modified: commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java?rev=1363177&r1=1363176&r2=1363177&view=diff
==============================================================================
--- commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java (original)
+++ commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java Wed Jul
18 23:47:49 2012
@@ -153,7 +153,7 @@ public abstract class LogFactory {
      * logDiagnostic method, so that users can clearly see which
      * LogFactory class is generating the output.
      */
-    private static String diagnosticPrefix;
+    private static final String diagnosticPrefix;
     
     /**
      * <p>Setting this system property 
@@ -1587,55 +1587,33 @@ public abstract class LogFactory {
      * output by setting the system property named {@link #DIAGNOSTICS_DEST_PROPERTY} to
      * a filename, or the special values STDOUT or STDERR. 
      */
-    private static void initDiagnostics() {
+    private static PrintStream initDiagnostics() {
         String dest;
         try {
             dest = getSystemProperty(DIAGNOSTICS_DEST_PROPERTY, null);
             if (dest == null) {
-                return;
+                return null;
             }
         } catch(SecurityException ex) {
             // We must be running in some very secure environment.
             // We just have to assume output is not wanted..
-            return;
+            return null;
         }
 
         if (dest.equals("STDOUT")) {
-            diagnosticsStream = System.out;
+            return System.out;
         } else if (dest.equals("STDERR")) {
-            diagnosticsStream = System.err;
+            return System.err;
         } else {
             try {
                 // open the file in append mode
                 FileOutputStream fos = new FileOutputStream(dest, true);
-                diagnosticsStream = new PrintStream(fos);
+                return new PrintStream(fos);
             } catch(IOException ex) {
                 // We should report this to the user - but how?
-                return;
-            }
-        }
-
-        // In order to avoid confusion where multiple instances of JCL are
-        // being used via different classloaders within the same app, we
-        // ensure each logged message has a prefix of form
-        // [LogFactory from classloader OID]
-        //
-        // Note that this prefix should be kept consistent with that 
-        // in LogFactoryImpl. However here we don't need to output info
-        // about the actual *instance* of LogFactory, as all methods that
-        // output diagnostics from this class are static.
-        String classLoaderName;
-        try {
-            ClassLoader classLoader = thisClassLoader;
-            if (thisClassLoader == null) {
-                classLoaderName = "BOOTLOADER";
-            } else {
-                classLoaderName = objectId(classLoader);
+                return null;
             }
-        } catch(SecurityException e) {
-            classLoaderName = "UNKNOWN";
         }
-        diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
     }
 
     /**
@@ -1832,7 +1810,28 @@ public abstract class LogFactory {
         // note: it's safe to call methods before initDiagnostics (though
         // diagnostic output gets discarded).
         thisClassLoader = getClassLoader(LogFactory.class);
-        initDiagnostics();
+        // In order to avoid confusion where multiple instances of JCL are
+        // being used via different classloaders within the same app, we
+        // ensure each logged message has a prefix of form
+        // [LogFactory from classloader OID]
+        //
+        // Note that this prefix should be kept consistent with that 
+        // in LogFactoryImpl. However here we don't need to output info
+        // about the actual *instance* of LogFactory, as all methods that
+        // output diagnostics from this class are static.
+        String classLoaderName;
+        try {
+            ClassLoader classLoader = thisClassLoader;
+            if (thisClassLoader == null) {
+                classLoaderName = "BOOTLOADER";
+            } else {
+                classLoaderName = objectId(classLoader);
+            }
+        } catch(SecurityException e) {
+            classLoaderName = "UNKNOWN";
+        }
+        diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
+        diagnosticsStream = initDiagnostics();
         logClassLoaderEnvironment(LogFactory.class);
         factories = createFactoryStore();
         if (isDiagnosticsEnabled()) {



Mime
View raw message