[FELIX-3373] File install logging doesn't notify user of important errors
Patch provided by Bert Jacobs

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1301356 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
index 4f966df..fbc9e26 100644
--- a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
+++ b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
@@ -129,7 +129,7 @@
         this.properties = properties;
         this.context = context;
         poll = getLong(properties, POLL, 2000);
-        logLevel = getInt(properties, LOG_LEVEL, 0);
+        logLevel = getInt(properties, LOG_LEVEL, Util.getGlobalLogLevel(context));
         originatingFileName = (String) properties.get(FILENAME);
         watchedDirectory = getFile(properties, DIR, new File("./load"));
         verifyWatchedDir();
@@ -368,7 +368,8 @@
                     }
                     catch (IOException e)
                     {
-                        log(Logger.LOG_WARNING,
+                        // Notify user of problem, won't retry until the dir is updated.
+                        log(Logger.LOG_ERROR,
                             "Unable to create jar for: " + file.getAbsolutePath(), e);
                         continue;
                     }
@@ -935,7 +936,7 @@
         }
         catch (Exception e)
         {
-            log(Logger.LOG_WARNING, "Failed to install artifact: " + path, e);
+            log(Logger.LOG_ERROR, "Failed to install artifact: " + path, e);
 
             // Add it our bad jars list, so that we don't
             // attempt to install it again and again until the underlying
@@ -1185,6 +1186,7 @@
             }
             catch (BundleException e)
             {
+                // Don't log this as an error, instead we start the bundle repeatedly.
                 log(Logger.LOG_WARNING, "Error while starting bundle: " + bundle.getLocation(), e);
             }
         }
diff --git a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/Util.java b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/Util.java
index 4cf4d64..66188d5 100644
--- a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/Util.java
+++ b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/Util.java
@@ -27,10 +27,6 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Collections;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
 import java.util.Set;
 import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
@@ -47,6 +43,11 @@
 {
     private static final String CHECKSUM_SUFFIX = ".checksum";
 
+    /**
+     * Returns the log level as defined in the BundleContext or System properties.
+     * @param context {@link BundleContext} of the FileInstall bundle.
+     * @return the global log level, or {@link Logger#LOG_ERROR}.
+     */
     public static int getGlobalLogLevel(BundleContext context)
     {
         String s = (String) context.getProperty(DirectoryWatcher.LOG_LEVEL);
@@ -54,7 +55,7 @@
             ? System.getProperty(DirectoryWatcher.LOG_LEVEL.toUpperCase().replace('.', '_'))
             : s;
         s = (s == null) ? "1" : s;
-        int logLevel = 1;
+        int logLevel = Logger.LOG_ERROR;
         try
         {
             logLevel = Integer.parseInt(s);
diff --git a/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java b/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
index 88c1f7c..22fc8f9 100644
--- a/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
+++ b/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
@@ -190,7 +190,7 @@
         assertTrue( "DIR parameter correctly read", dw.watchedDirectory.getAbsolutePath().endsWith(
             "src" + File.separatorChar + "test" + File.separatorChar + "resources" ) );
         assertEquals( "Default POLL parameter correctly read", 2000l, dw.poll );
-        assertEquals( "Default LOG_LEVEL parameter correctly read", 0, dw.logLevel );
+        assertEquals( "Default LOG_LEVEL parameter correctly read", 1, dw.logLevel );
         assertTrue( "Default TMPDIR parameter correctly read", dw.tmpDir.getAbsolutePath().startsWith(
                 new File(System.getProperty("java.io.tmpdir")).getAbsolutePath()) );
         assertEquals( "Default START_NEW_BUNDLES parameter correctly read", true, dw.startBundles );