[asterisk-scf-commits] team/dlee/jlogger.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Nov 24 16:51:12 CST 2010


branch "master" has been updated
       via  335843c6d9fff6731e9489e6c541cc9430082523 (commit)
       via  a85a543d67503225629172630227f3c240f39c6d (commit)
       via  ea3c6e2e09fd936d3022d5e51d84fe3bba959736 (commit)
       via  d584e133d15bed91ac4c9b8a057f81def9cd99c2 (commit)
       via  5d985ba9cd4d1d0fff9b2ac62c040e3729a93874 (commit)
       via  f74d3f3436b92c47a564a66a4802d8f0aa9aa429 (commit)
      from  9de372f1d3247b1c33427125a19896d2a9303239 (commit)

Summary of changes:
 jlogger.ipr                                        |    1 +
 pom.xml                                            |   17 ++++++++++++
 .../asterisk/scf/jlogging/AsteriskScfLogger.java   |   27 ++++++++++++-------
 .../scf/jlogging/AsteriskScfLoggerFactory.java     |   12 ++++----
 .../java/org/asterisk/scf/jlogging/IceLogger.java  |   26 ++++++++++++++-----
 .../asterisk/scf/jlogging/IceIntegrationTest.java  |   17 +++---------
 .../scf/jlogging/MockableServiceLocator.java       |   23 +++++++++++------
 7 files changed, 79 insertions(+), 44 deletions(-)


- Log -----------------------------------------------------------------
commit 335843c6d9fff6731e9489e6c541cc9430082523
Author: David M. Lee <dlee at digium.com>
Date:   Wed Nov 24 15:53:09 2010 -0600

    Better debug output.
    
    * Log stack traces
    * Local messages are prefixed with (Logger)
    * Added some debug statements

diff --git a/src/main/java/org/asterisk/scf/jlogging/AsteriskScfLogger.java b/src/main/java/org/asterisk/scf/jlogging/AsteriskScfLogger.java
index a4c6aba..10811e1 100644
--- a/src/main/java/org/asterisk/scf/jlogging/AsteriskScfLogger.java
+++ b/src/main/java/org/asterisk/scf/jlogging/AsteriskScfLogger.java
@@ -21,6 +21,8 @@ import org.slf4j.Logger;
 import org.slf4j.helpers.MarkerIgnoringBase;
 import org.slf4j.helpers.MessageFormatter;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -30,7 +32,7 @@ import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * {@link Logger} which logs to the Asterisk SCF logging server.
- *
+ * <p/>
  * This class is final for the slight performance optimization that gives by
  * being able to inline methods.
  */
@@ -89,7 +91,7 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
 
     @Override
     public void debug(String msg) {
-        logs(Level.Debug, msg);
+        debug(msg, (Throwable) null);
     }
 
     @Override
@@ -109,7 +111,7 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
 
     @Override
     public void debug(String msg, Throwable t) {
-        debug(msg + ": " + t.getMessage());
+        logs(Level.Debug, msg, t);
     }
 
     @Override
@@ -119,7 +121,7 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
 
     @Override
     public void info(String msg) {
-        logs(Level.Info, msg);
+        info(msg, (Throwable) null);
     }
 
     @Override
@@ -139,7 +141,7 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
 
     @Override
     public void info(String msg, Throwable t) {
-        info(msg + ": " + t.getMessage());
+        logs(Level.Info, msg, t);
     }
 
     @Override
@@ -149,7 +151,7 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
 
     @Override
     public void warn(String msg) {
-        logs(Level.Warning, msg);
+        warn(msg, (Throwable) null);
     }
 
     @Override
@@ -169,7 +171,7 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
 
     @Override
     public void warn(String msg, Throwable t) {
-        warn(msg + ": " + t.getMessage());
+        logs(Level.Warning, msg, t);
     }
 
     @Override
@@ -179,7 +181,7 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
 
     @Override
     public void error(String msg) {
-        logs(Level.Error, msg);
+        error(msg, (Throwable) null);
     }
 
     @Override
@@ -199,7 +201,7 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
 
     @Override
     public void error(String msg, Throwable t) {
-        error(msg + ": " + t.getMessage());
+        logs(Level.Error, msg, t);
     }
 
     public AsteriskScfLogger getParent() {
@@ -248,10 +250,15 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
         }
     }
 
-    private void logs(Level level, String msg) {
+    private void logs(Level level, String msg, Throwable t) {
         LogOut logOut = this.logOut.get();
         if (logOut != null && isEnabledFor(level)) {
             logOut.logs(name, level, msg);
+            if (t != null) {
+                StringWriter stackTrace = new StringWriter();
+                t.printStackTrace(new PrintWriter(stackTrace));
+                logOut.logs(name, level, stackTrace.toString());
+            }
         }
     }
 
diff --git a/src/main/java/org/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java b/src/main/java/org/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java
index 0b638c0..405891b 100644
--- a/src/main/java/org/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java
+++ b/src/main/java/org/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java
@@ -78,13 +78,13 @@ public class AsteriskScfLoggerFactory implements ILoggerFactory {
 
                 topic.subscribeAndGetPublisher(null, proxy);
                 adapter.activate();
-                return;
+            } else {
+                System.err.println("(Logger) Could not obtain proxy to TopicManager.");
             }
         } catch (Exception e) {
-            System.err.println("Exception trying to register with Ice topic.");
+            System.err.println("(Logger) Failed to subscribe to " + ServerConfigurationTopic.value);
             e.printStackTrace(System.err);
         }
-        System.err.println("Could not obtain proxy to TopicManager.");
     }
 
     public static void initialize(ObjectAdapter adapter) {
diff --git a/src/main/java/org/asterisk/scf/jlogging/IceLogger.java b/src/main/java/org/asterisk/scf/jlogging/IceLogger.java
index f94d9fd..b6d4460 100644
--- a/src/main/java/org/asterisk/scf/jlogging/IceLogger.java
+++ b/src/main/java/org/asterisk/scf/jlogging/IceLogger.java
@@ -70,7 +70,7 @@ public class IceLogger implements LogOut {
                 logged = true;
             }
         } catch (Exception e) {
-            System.err.println("Failed to contact LoggerServer: " + e.getMessage());
+            System.err.println("(Logger) Failed to contact LoggerServer: " + e.getMessage());
             e.printStackTrace(System.err);
         }
 
@@ -79,9 +79,9 @@ public class IceLogger implements LogOut {
             if (!hasPrintedNoServerNotice) {
                 hasPrintedNoServerNotice = true;
                 System.err.println(
-                        "!!! unable to log to server.  logging to stdout instead.");
+                        "!!! unable to log to server.  logging to stderr instead.");
             }
-            System.out.printf("%s:%s:%s\n", name, logLevel.name(), message);
+            System.err.printf("%s:%s:%s\n", name, logLevel.name(), message);
         }
     }
 
@@ -113,7 +113,7 @@ public class IceLogger implements LogOut {
                         .propertyToProxy("LocatorService.Proxy")
                         .ice_collocationOptimized(false));
         if (locator == null) {
-            System.err.println("LocatorService.Proxy not set.  Cannot find " + LoggingServerGuid.value);
+            System.err.println("(Logger) LocatorService.Proxy not set.  Cannot find " + LoggingServerGuid.value);
         }
 
         IceLogger r = new IceLogger();
@@ -129,11 +129,11 @@ public class IceLogger implements LogOut {
                     topic.subscribeAndGetPublisher(null, proxy);
                 }
             } else {
-                System.err.println("TopicManager.Proxy not set.  Will not receive updates.");
+                System.err.println("(Logger) TopicManager.Proxy not set.  Will not receive updates.");
             }
             listener.updateLoggerFromServiceLocator();
         } catch (Exception e) {
-            System.err.println("Failed to subscribe to " + TOPIC.value);
+            System.err.println("(Logger) Failed to subscribe to " + TOPIC.value);
             e.printStackTrace(System.err);
         }
         return r;
@@ -202,6 +202,9 @@ public class IceLogger implements LogOut {
                     setServer(null);
                 }
             }
+            if (getServer() == null) {
+                System.err.println("(Logger) Failed to locate LoggingServer");
+            }
         }
     }
 }

commit a85a543d67503225629172630227f3c240f39c6d
Author: David M. Lee <dlee at digium.com>
Date:   Wed Nov 24 15:25:17 2010 -0600

    Catch possible exception from checkedCast.

diff --git a/src/main/java/org/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java b/src/main/java/org/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java
index 2cdc44d..0b638c0 100644
--- a/src/main/java/org/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java
+++ b/src/main/java/org/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java
@@ -67,10 +67,10 @@ public class AsteriskScfLoggerFactory implements ILoggerFactory {
 
         Communicator communicator = adapter.getCommunicator();
 
-        TopicManagerPrx topicManager = TopicManagerPrxHelper.checkedCast(
-                communicator.propertyToProxy("TopicManager.Proxy"));
-
         try {
+            TopicManagerPrx topicManager = TopicManagerPrxHelper.checkedCast(
+                    communicator.propertyToProxy("TopicManager.Proxy"));
+
             if (topicManager != null) {
                 TopicPrx topic = topicManager.retrieve(ServerConfigurationTopic.value);
                 IceConfigurator r = new IceConfigurator();

commit ea3c6e2e09fd936d3022d5e51d84fe3bba959736
Author: David M. Lee <dlee at digium.com>
Date:   Wed Nov 24 15:24:20 2010 -0600

    Improved no server message.

diff --git a/src/main/java/org/asterisk/scf/jlogging/IceLogger.java b/src/main/java/org/asterisk/scf/jlogging/IceLogger.java
index 6678ffe..f94d9fd 100644
--- a/src/main/java/org/asterisk/scf/jlogging/IceLogger.java
+++ b/src/main/java/org/asterisk/scf/jlogging/IceLogger.java
@@ -39,6 +39,7 @@ import java.util.concurrent.atomic.AtomicReference;
 
 public class IceLogger implements LogOut {
     private AtomicReference<LoggingServerPrx> server;
+    private boolean hasPrintedNoServerNotice = false;
 
     public IceLogger() {
         this(null);
@@ -75,7 +76,12 @@ public class IceLogger implements LogOut {
 
         if (!logged) {
             // no server, log to stdout
-            System.out.printf("(no server) %s:%s:%s\n", name, logLevel.name(), message);
+            if (!hasPrintedNoServerNotice) {
+                hasPrintedNoServerNotice = true;
+                System.err.println(
+                        "!!! unable to log to server.  logging to stdout instead.");
+            }
+            System.out.printf("%s:%s:%s\n", name, logLevel.name(), message);
         }
     }
 

commit d584e133d15bed91ac4c9b8a057f81def9cd99c2
Author: David M. Lee <dlee at digium.com>
Date:   Wed Nov 24 15:22:56 2010 -0600

    Specify LoggingServerCategory for location.

diff --git a/src/main/java/org/asterisk/scf/jlogging/IceLogger.java b/src/main/java/org/asterisk/scf/jlogging/IceLogger.java
index d1002b2..6678ffe 100644
--- a/src/main/java/org/asterisk/scf/jlogging/IceLogger.java
+++ b/src/main/java/org/asterisk/scf/jlogging/IceLogger.java
@@ -23,6 +23,7 @@ import AsteriskSCF.Core.Discovery.V1.ServiceNotFound;
 import AsteriskSCF.System.Discovery.TOPIC;
 import AsteriskSCF.System.Discovery._EventsDisp;
 import AsteriskSCF.System.Logging.Level;
+import AsteriskSCF.System.Logging.LoggingServerCategory;
 import AsteriskSCF.System.Logging.LoggingServerGuid;
 import AsteriskSCF.System.Logging.LoggingServerPrx;
 import AsteriskSCF.System.Logging.LoggingServerPrxHelper;
@@ -184,7 +185,7 @@ public class IceLogger implements LogOut {
         private void updateLoggerFromServiceLocator() {
             if (locator != null) {
                 try {
-                    ServiceLocatorParams locatorParams = new ServiceLocatorParams();
+                    ServiceLocatorParams locatorParams = new ServiceLocatorParams(LoggingServerCategory.value);
                     ObjectPrx serverObject = locator.locate(locatorParams);
                     if (serverObject != null) {
                         LoggingServerPrx server = LoggingServerPrxHelper.checkedCast(serverObject);

commit 5d985ba9cd4d1d0fff9b2ac62c040e3729a93874
Author: David M. Lee <dlee at digium.com>
Date:   Wed Nov 24 15:21:32 2010 -0600

    always install sources

diff --git a/pom.xml b/pom.xml
index ddd0f4a..3831416 100644
--- a/pom.xml
+++ b/pom.xml
@@ -61,8 +61,25 @@
                         <target>${java.version}</target>
                     </configuration>
                 </plugin>
+                <plugin>
+                    <artifactId>maven-source-plugin</artifactId>
+                    <executions>
+                        <execution>
+                            <id>attach-sources</id>
+                            <phase>verify</phase>
+                            <goals>
+                                <goal>jar</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                </plugin>
             </plugins>
         </pluginManagement>
+        <plugins>
+            <plugin>
+                <artifactId>maven-source-plugin</artifactId>
+            </plugin>
+        </plugins>
     </build>
 
     <reporting>

commit f74d3f3436b92c47a564a66a4802d8f0aa9aa429
Author: David M. Lee <dlee at digium.com>
Date:   Tue Nov 23 15:22:36 2010 -0600

    AMD updates to ServiceDiscovery.

diff --git a/jlogger.ipr b/jlogger.ipr
index 209d7ee..3646ac1 100644
--- a/jlogger.ipr
+++ b/jlogger.ipr
@@ -242,6 +242,7 @@
       </JAVADOC>
       <SOURCES>
         <root url="jar://$MAVEN_REPOSITORY$/com/zeroc/ice/3.4.1-digium/ice-3.4.1-digium-sources.jar!/" />
+        <root url="file://$PROJECT_DIR$/../asterisk-scf/ice/java/src" />
       </SOURCES>
     </library>
     <library name="Maven: org.slf4j:slf4j-api:1.6.1">
diff --git a/src/main/java/org/asterisk/scf/jlogging/IceLogger.java b/src/main/java/org/asterisk/scf/jlogging/IceLogger.java
index ef7d504..d1002b2 100644
--- a/src/main/java/org/asterisk/scf/jlogging/IceLogger.java
+++ b/src/main/java/org/asterisk/scf/jlogging/IceLogger.java
@@ -102,7 +102,9 @@ public class IceLogger implements LogOut {
         }
 
         ServiceLocatorPrx locator = ServiceLocatorPrxHelper.uncheckedCast(
-                communicator.propertyToProxy("LocatorService.Proxy"));
+                communicator
+                        .propertyToProxy("LocatorService.Proxy")
+                        .ice_collocationOptimized(false));
         if (locator == null) {
             System.err.println("LocatorService.Proxy not set.  Cannot find " + LoggingServerGuid.value);
         }
diff --git a/src/test/java/org/asterisk/scf/jlogging/IceIntegrationTest.java b/src/test/java/org/asterisk/scf/jlogging/IceIntegrationTest.java
index 22b5c92..786fd14 100644
--- a/src/test/java/org/asterisk/scf/jlogging/IceIntegrationTest.java
+++ b/src/test/java/org/asterisk/scf/jlogging/IceIntegrationTest.java
@@ -17,7 +17,6 @@
 package org.asterisk.scf.jlogging;
 
 import AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams;
-import AsteriskSCF.Core.Discovery.V1.ServiceNotFound;
 import AsteriskSCF.System.Logging.Level;
 import Ice.Communicator;
 import Ice.ObjectAdapter;
@@ -29,19 +28,16 @@ import org.junit.Before;
 import org.junit.Test;
 
 import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.*;
 
 public class IceIntegrationTest {
     private AsteriskScfLoggerFactory uut;
 
     private Communicator communicator;
-    private ObjectAdapter adapter;
 
     private Mockery context;
     private MockableLoggingServer loggingServer;
     private MockableServiceLocator serviceLocator;
 
-    private ObjectPrx serviceLocatorPrx;
     private ObjectPrx loggingServerPrx;
 
 
@@ -53,22 +49,17 @@ public class IceIntegrationTest {
         serviceLocator = new MockableServiceLocator(context);
 
         communicator = Ice.Util.initialize();
-        adapter = communicator.createObjectAdapterWithEndpoints("adapter", "default");
+        ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("adapter", "default");
 
-        serviceLocatorPrx = adapter.addWithUUID(serviceLocator);
+        ObjectPrx serviceLocatorPrx = adapter.addWithUUID(serviceLocator);
         communicator.getProperties().setProperty("LocatorService.Proxy", serviceLocatorPrx.toString());
 
         loggingServerPrx = adapter.addWithUUID(loggingServer);
         adapter.activate();
 
         context.checking(new Expectations() {{
-            try {
-
-                one(serviceLocator.getMock()).locate(with(any(ServiceLocatorParams.class)));
-                will(returnValue(loggingServerPrx));
-            } catch (ServiceNotFound serviceNotFound) {
-                fail("Exception from mock?!?");
-            }
+            one(serviceLocator.getMock()).locate(with(any(ServiceLocatorParams.class)));
+            will(returnValue(loggingServerPrx));
         }});
 
         uut = new AsteriskScfLoggerFactory();
diff --git a/src/test/java/org/asterisk/scf/jlogging/MockableServiceLocator.java b/src/test/java/org/asterisk/scf/jlogging/MockableServiceLocator.java
index c3c76c4..2fa4f7c 100644
--- a/src/test/java/org/asterisk/scf/jlogging/MockableServiceLocator.java
+++ b/src/test/java/org/asterisk/scf/jlogging/MockableServiceLocator.java
@@ -16,7 +16,8 @@
 
 package org.asterisk.scf.jlogging;
 
-import AsteriskSCF.Core.Discovery.V1.ServiceLocator;
+import AsteriskSCF.Core.Discovery.V1.AMD_ServiceLocator_locate;
+import AsteriskSCF.Core.Discovery.V1.AMD_ServiceLocator_locateAll;
 import AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams;
 import AsteriskSCF.Core.Discovery.V1.ServiceNotFound;
 import AsteriskSCF.Core.Discovery.V1._ServiceLocatorDisp;
@@ -25,23 +26,29 @@ import Ice.ObjectPrx;
 import org.jmock.Mockery;
 
 public class MockableServiceLocator extends _ServiceLocatorDisp {
-    private ServiceLocator mock;
+    public interface ServiceLocatorIfc {
+        public ObjectPrx locate(ServiceLocatorParams params);
+
+        public ObjectPrx[] locateAll(ServiceLocatorParams params);
+    }
+
+    private ServiceLocatorIfc mock;
 
     public MockableServiceLocator(Mockery context) {
-        mock = context.mock(ServiceLocator.class);
+        mock = context.mock(ServiceLocatorIfc.class);
     }
 
     @Override
-    public ObjectPrx locate(ServiceLocatorParams params, Current __current) throws ServiceNotFound {
-        return mock.locate(params);
+    public void locate_async(AMD_ServiceLocator_locate cb, ServiceLocatorParams params, Current __current) throws ServiceNotFound {
+        cb.ice_response(mock.locate(params));
     }
 
     @Override
-    public ObjectPrx[] locateAll(ServiceLocatorParams params, Current __current) throws ServiceNotFound {
-        return mock.locateAll(params);
+    public void locateAll_async(AMD_ServiceLocator_locateAll cb, ServiceLocatorParams params, Current __current) throws ServiceNotFound {
+        cb.ice_response(mock.locateAll(params));
     }
 
-    public ServiceLocator getMock() {
+    public ServiceLocatorIfc getMock() {
         return mock;
     }
 }

-----------------------------------------------------------------------


-- 
team/dlee/jlogger.git



More information about the asterisk-scf-commits mailing list