ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1339402 - /ace/trunk/ace-managementagent/src/main/java/org/apache/ace/managementagent/Activator.java
Date Wed, 16 May 2012 22:25:55 GMT
Author: marrs
Date: Wed May 16 22:25:55 2012
New Revision: 1339402

URL: http://svn.apache.org/viewvc?rev=1339402&view=rev
Log:
Added support for logging to the console. Enable with system property log=true.

Modified:
    ace/trunk/ace-managementagent/src/main/java/org/apache/ace/managementagent/Activator.java

Modified: ace/trunk/ace-managementagent/src/main/java/org/apache/ace/managementagent/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-managementagent/src/main/java/org/apache/ace/managementagent/Activator.java?rev=1339402&r1=1339401&r2=1339402&view=diff
==============================================================================
--- ace/trunk/ace-managementagent/src/main/java/org/apache/ace/managementagent/Activator.java
(original)
+++ ace/trunk/ace-managementagent/src/main/java/org/apache/ace/managementagent/Activator.java
Wed May 16 22:25:55 2012
@@ -10,12 +10,17 @@ import org.apache.felix.dm.DependencyAct
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.log.LogService;
 
 public class Activator extends DependencyActivatorBase {
 
     private final boolean m_quiet = Boolean.parseBoolean(System.getProperty("quiet", "false"));
+    private final boolean m_logToConsole = Boolean.parseBoolean(System.getProperty("log",
"false"));
+
     private final BundleActivator[] m_activators = new BundleActivator[] {
         new org.apache.ace.deployment.deploymentadmin.Activator(),
         new org.apache.ace.deployment.service.impl.Activator(),
@@ -50,6 +55,56 @@ public class Activator extends Dependenc
      */
     @Override
     public void init(BundleContext context, DependencyManager manager) throws Exception {
+        if (m_logToConsole) {
+        	manager.add(createComponent()
+        		.setInterface(LogService.class.getName(), null)
+        		.setImplementation(new LogService() {
+        		    private String[] LEVEL = { "", "Error", "Warn ", "Info ", "Debug" };
+
+        		    public void log(int level, String message) {
+        		        log(null, level, message, null);
+        		    }
+
+        		    public void log(int level, String message, Throwable throwable) {
+        		        log(null, level, message, throwable);
+        		    }
+
+        		    public void log(ServiceReference reference, int level, String message) {
+        		        log(reference, level, message, null);
+        		    }
+
+        		    public void log(ServiceReference reference, int level, String message, Throwable
throwable) {
+        		        String bundle = " [   ]";
+        		        String service = " ";
+        		        if (reference != null) {
+        		            bundle = "00" + reference.getBundle().getBundleId();
+        		            bundle = " [" + bundle.substring(bundle.length() - 3) + "]";
+        		            Object objectClass = reference.getProperty(Constants.OBJECTCLASS);
+        		            if (objectClass instanceof String[]) {
+        		                StringBuffer buffer = new StringBuffer();
+        		                String[] objClassArr = ((String[]) objectClass);
+        		                for (int i = 0; i < objClassArr.length; i++) {
+        		                    String svc = objClassArr[i];
+        		                    if (buffer.length() > 0) {
+        		                        buffer.append(';');
+        		                    }
+        		                    buffer.append(svc);
+        		                    service = buffer.toString() + ": ";
+        		                }
+        		            }
+        		            else {
+        		                service = objectClass.toString() + ": ";
+        		            }
+        		        }
+        		        System.out.println("[" + LEVEL[level] + "]" + bundle + service + message);
+        		        if (throwable != null) {
+        		            throwable.printStackTrace();
+        		        }
+        		    }
+				})
+        	);
+        }
+        
         for (int i = 0; i < m_activators.length; i++) {
             BundleActivator a = m_activators[i];
             // start the bundle unless there is a system property with the same package name
as



Mime
View raw message