felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1583669 - in /felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal: DirectoryWatcher.java Util.java
Date Tue, 01 Apr 2014 13:48:02 GMT
Author: gnodet
Date: Tue Apr  1 13:48:02 2014
New Revision: 1583669

URL: http://svn.apache.org/r1583669
Log:
[FELIX-4475] Improve logging in FileInstall
Allow delegating to jul instead of stdout

Modified:
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/Util.java

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java?rev=1583669&r1=1583668&r2=1583669&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
(original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
Tue Apr  1 13:48:02 2014
@@ -91,6 +91,7 @@ public class DirectoryWatcher extends Th
     public final static String POLL = "felix.fileinstall.poll";
     public final static String DIR = "felix.fileinstall.dir";
     public final static String LOG_LEVEL = "felix.fileinstall.log.level";
+    public final static String LOG_DEFAULT = "felix.fileinstall.log.default";
     public final static String TMPDIR = "felix.fileinstall.tmpdir";
     public final static String FILTER = "felix.fileinstall.filter";
     public final static String START_NEW_BUNDLES = "felix.fileinstall.bundles.new.start";
@@ -110,6 +111,9 @@ public class DirectoryWatcher extends Th
     public final static String SCOPE_MANAGED = "managed";
     public final static String SCOPE_ALL = "all";
 
+    public final static String LOG_STDOUT = "stdout";
+    public final static String LOG_JUL = "jul";
+
     static final SecureRandom random = new SecureRandom();
 
     final File javaIoTmpdir = new File(System.getProperty("java.io.tmpdir"));

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/Util.java?rev=1583669&r1=1583668&r2=1583669&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/Util.java
(original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/Util.java
Tue Apr  1 13:48:02 2014
@@ -30,6 +30,7 @@ import java.util.Collections;
 import java.util.Set;
 import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
+import java.util.logging.Level;
 import java.util.zip.Deflater;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
@@ -99,7 +100,7 @@ public class Util
         }
         catch (Throwable t)
         {
-            logger = new StdOutLogger();
+            logger = new DefaultLogger(context);
         }
         return logger;
     }
@@ -117,8 +118,21 @@ public class Util
         void log(int logLevel, int msgLevel, String message, Throwable throwable);
     }
 
-    static class StdOutLogger implements Logger
+    static class DefaultLogger implements Logger
     {
+        protected BundleContext context;
+        private final String logDefault;
+
+        DefaultLogger(BundleContext context)
+        {
+            this.context = context;
+            String s = context.getProperty(DirectoryWatcher.LOG_DEFAULT);
+            s = (s == null)
+                    ? System.getProperty(DirectoryWatcher.LOG_DEFAULT.toUpperCase().replace('.',
'_'))
+                    : s;
+            logDefault = (s == null) ? DirectoryWatcher.LOG_STDOUT : s;
+        }
+
         public boolean isValidLogger(BundleContext context)
         {
             return true;
@@ -131,22 +145,37 @@ public class Util
             // level.
             if ((logLevel > 0) && (msgLevel <= logLevel))
             {
-                System.out.println(message + ((throwable == null) ? "" : ": " + throwable));
-                if (throwable != null)
+                if (DirectoryWatcher.LOG_JUL.equals(logDefault))
+                {
+                    Level lvl;
+                    switch (msgLevel)
+                    {
+                        case 1:  lvl = Level.SEVERE; break;
+                        case 2:  lvl = Level.WARNING; break;
+                        case 3:  lvl = Level.INFO; break;
+                        case 4:  lvl = Level.FINE; break;
+                        default: lvl = Level.FINEST; break;
+                    }
+                    java.util.logging.Logger logger = java.util.logging.Logger.getLogger("fileinstall");
+                    logger.log(lvl, message, throwable);
+                }
+                else
                 {
-                    throwable.printStackTrace(System.out);
+                    System.out.println(message + ((throwable == null) ? "" : ": " + throwable));
+                    if (throwable != null)
+                    {
+                        throwable.printStackTrace(System.out);
+                    }
                 }
             }
         }
     }
 
-    static class OsgiLogger extends StdOutLogger
+    static class OsgiLogger extends DefaultLogger
     {
-        private BundleContext context;
-
         OsgiLogger(BundleContext context)
         {
-            this.context = context;
+            super(context);
             // Now make sure we can access the LogService class
             try
             {



Mime
View raw message