karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [01/11] git commit: [KARAF-2864] The internal logger for the felix framework is not configured
Date Tue, 01 Apr 2014 11:43:34 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 166b9c6fb -> 17095271c


[KARAF-2864] The internal logger for the felix framework is not configured

This is a bit of a hack, but we can't do much without any real enhancement in felix


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/99234484
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/99234484
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/99234484

Branch: refs/heads/master
Commit: 9923448481e7d52f3f7e2a1e1e9241a7a15f5df8
Parents: 504dbca
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Sat Mar 29 14:09:49 2014 +0100
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Tue Apr 1 10:14:56 2014 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/karaf/main/Main.java   | 29 ++++++++++++++++++++
 1 file changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/99234484/main/src/main/java/org/apache/karaf/main/Main.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/Main.java b/main/src/main/java/org/apache/karaf/main/Main.java
index 2ebd2ff..69ce6e2 100644
--- a/main/src/main/java/org/apache/karaf/main/Main.java
+++ b/main/src/main/java/org/apache/karaf/main/Main.java
@@ -22,7 +22,9 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.net.URI;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -31,6 +33,7 @@ import java.security.Security;
 import java.util.ArrayList;
 import java.util.List;
 import org.apache.felix.utils.properties.Properties;
+
 import java.util.StringTokenizer;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -50,6 +53,7 @@ import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 import org.osgi.framework.FrameworkEvent;
 import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.launch.Framework;
 import org.osgi.framework.launch.FrameworkFactory;
 import org.osgi.framework.startlevel.BundleStartLevel;
@@ -234,6 +238,31 @@ public class Main {
         ClassLoader classLoader = createClassLoader(resolver);
         FrameworkFactory factory = loadFrameworkFactory(classLoader);
         framework = factory.newFramework(new StringMap(config.props, false));
+
+        // Hack to set felix logger
+        try {
+            Field field = framework.getClass().getDeclaredField("m_logger");
+            field.setAccessible(true);
+            Object logger = field.get(framework);
+            Method method = logger.getClass().getDeclaredMethod("setLogger", Object.class);
+            method.setAccessible(true);
+            method.invoke(logger, new Object() {
+                public void log(ServiceReference sr, int level, String message, Throwable
exception) {
+                    Level lvl;
+                    switch (level) {
+                        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;
+                    }
+                    Logger.getLogger("Felix").log(lvl, message, exception);
+                }
+            });
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+
         framework.init();
         framework.getBundleContext().addFrameworkListener(lockCallback);
         framework.start();


Mime
View raw message