You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/01/23 08:15:01 UTC

[GitHub] JaroslavTulach closed pull request #382: Use logger level for felix.

JaroslavTulach closed pull request #382: Use logger level for felix.
URL: https://github.com/apache/incubator-netbeans/pull/382
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core.netigso/src/org/netbeans/core/netigso/Netigso.java b/core.netigso/src/org/netbeans/core/netigso/Netigso.java
index bad7d6b04..6efa82cc6 100644
--- a/core.netigso/src/org/netbeans/core/netigso/Netigso.java
+++ b/core.netigso/src/org/netbeans/core/netigso/Netigso.java
@@ -125,7 +125,8 @@ protected void prepare(Lookup lkp, Collection<? extends Module> preregister) {
             activator = new NetigsoActivator(this);
             configMap.put("netigso.archive", NetigsoArchiveFactory.DEFAULT.create(this)); // NOI18N
             if (!configMap.containsKey("felix.log.level")) { // NOI18N
-              configMap.put("felix.log.level", "4"); // NOI18N - allow others to set log level
+                String felixLevel = felixLogLevel(LOG);
+                configMap.put("felix.log.level", felixLevel); // NOI18N
             }
             configMap.put("felix.bootdelegation.classloaders", activator); // NOI18N
             String startLevel = FRAMEWORK_START_LEVEL();
@@ -157,6 +158,20 @@ protected void prepare(Lookup lkp, Collection<? extends Module> preregister) {
         }
     }
 
+    static String felixLogLevel(final Logger log) {
+        String felixLevel = "1"; // NOI18N
+        if (log.isLoggable(Level.WARNING)) {
+            felixLevel = "2"; // NOI18N
+        }
+        if (log.isLoggable(Level.CONFIG)) {
+            felixLevel = "3"; // NOI18N
+        }
+        if (log.isLoggable(Level.FINE)) {
+            felixLevel = "4"; // NOI18N
+        }
+        return felixLevel;
+    }
+
     @Override
     protected Set<String> start(Collection<? extends Module> allModules) {
         return toActivate(framework, allModules);
diff --git a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoLogTest.java b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoLogTest.java
new file mode 100644
index 000000000..a9d4e271e
--- /dev/null
+++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoLogTest.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.core.netigso;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertFalse;
+import static junit.framework.TestCase.assertTrue;
+import org.junit.Test;
+
+public class NetigsoLogTest {
+    @Test
+    public void testConvertLogsSevere() {
+        assertLog(Level.SEVERE, "1");
+    }
+
+    @Test
+    public void testConvertLogsWarning() {
+        assertLog(Level.WARNING, "2");
+    }
+
+    @Test
+    public void testConvertLogsInfo() {
+        assertLog(Level.INFO, "2");
+    }
+
+    @Test
+    public void testConvertLogsConfig() {
+        assertLog(Level.CONFIG, "3");
+    }
+
+    @Test
+    public void testConvertLogsFineAndLess() {
+        assertLog(Level.FINE, "4");
+        assertLog(Level.FINER, "4");
+        assertLog(Level.FINEST, "4");
+    }
+
+    private static void assertLog(Level level, String felixLevel) {
+        Logger l = Logger.getLogger("my.test.logger." + level);
+        l.setLevel(level);
+        assertTrue("Level is loggable", l.isLoggable(level));
+        Level less = new Level("", level.intValue() - 100) {};
+        assertFalse("Lowever level isn't loggable", l.isLoggable(less));
+
+        String convertedLevel = Netigso.felixLogLevel(l);
+        assertEquals(felixLevel, convertedLevel);
+    }
+
+}
diff --git a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoTest.java b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoTest.java
index 07c70361b..8d0d896f7 100644
--- a/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoTest.java
+++ b/core.netigso/test/unit/src/org/netbeans/core/netigso/NetigsoTest.java
@@ -26,7 +26,6 @@
 import org.netbeans.MockEvents;
 import org.netbeans.Module;
 import org.netbeans.ModuleManager;
-import org.netbeans.core.startup.Main;
 import org.netbeans.junit.RandomlyFails;
 
 /**


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists