[asterisk-scf-commits] team/dlee/jlogger.git branch "master" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Thu Nov 18 12:44:27 CST 2010
branch "master" has been created
at 1800798308c06087c475479ff70872bae6abae61 (commit)
- Log -----------------------------------------------------------------
commit 1800798308c06087c475479ff70872bae6abae61
Author: David M. Lee <dlee at digium.com>
Date: Thu Nov 18 12:41:05 2010 -0600
Added initialization functions.
diff --git a/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java b/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java
index 065f64d..079f7b1 100644
--- a/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java
+++ b/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java
@@ -28,6 +28,7 @@ import IceStorm.TopicManagerPrx;
import IceStorm.TopicManagerPrxHelper;
import IceStorm.TopicPrx;
import org.slf4j.ILoggerFactory;
+import org.slf4j.impl.StaticLoggerBinder;
import java.util.ArrayList;
import java.util.Arrays;
@@ -86,6 +87,20 @@ public class AsteriskScfLoggerFactory implements ILoggerFactory {
System.err.println("Could not obtain proxy to TopicManager.");
}
+ public static void initialize(ObjectAdapter adapter) {
+ initialize(StaticLoggerBinder.getSingleton().getLoggerFactory(), adapter);
+ }
+
+ public static void initialize(ILoggerFactory instance, ObjectAdapter adapter) {
+ if (instance == null) {
+ throw new IllegalArgumentException("Cannot initialize null instance");
+ }
+ if (instance instanceof AsteriskScfLoggerFactory) {
+ AsteriskScfLoggerFactory i = (AsteriskScfLoggerFactory) instance;
+ i.setAdapter(adapter);
+ }
+ }
+
public class IceConfigurator extends _ServerConfigurationListenerDisp {
@Override
commit 9940f605f78b505c67cbd9e4751f1e11cd7225fc
Author: David M. Lee <dlee at digium.com>
Date: Thu Nov 18 10:35:37 2010 -0600
Clean-ups and unit tests.
diff --git a/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLogger.java b/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLogger.java
index 846cd12..93095a2 100644
--- a/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLogger.java
+++ b/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLogger.java
@@ -17,38 +17,41 @@
package com.digium.asterisk.scf.jlogging;
import AsteriskSCF.System.Logging.Level;
+import org.slf4j.Logger;
import org.slf4j.helpers.MarkerIgnoringBase;
import org.slf4j.helpers.MessageFormatter;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+/**
+ * {@link Logger} which logs to the Asterisk SCF logging server.
+ *
+ * This class is final for the slight performance optimization that gives by
+ * being able to inline methods.
+ */
public final class AsteriskScfLogger extends MarkerIgnoringBase {
- private AsteriskScfLogger parent = null;
- private Map<String, AsteriskScfLogger> children = new HashMap<String, AsteriskScfLogger>();
- private Level level = null;
+ private final AsteriskScfLogger parent;
+ private final Map<String, AsteriskScfLogger> children =
+ Collections.synchronizedMap(new HashMap<String, AsteriskScfLogger>());
+ private AtomicReference<Level> level = new AtomicReference<Level>();
- private LogOut logOut;
+ private AtomicReference<LogOut> logOut = new AtomicReference<LogOut>();
public AsteriskScfLogger(String name, AsteriskScfLogger parent, LogOut logOut) {
this.name = name;
this.parent = parent;
- this.logOut = logOut;
+ this.logOut.set(logOut);
}
public AsteriskScfLogger(String name) {
this(name, null, null);
}
- private Level getEffectiveLevel() {
- if (level == null) {
- return (parent == null) ? Level.Debug : parent.getEffectiveLevel();
- } else {
- return level;
- }
- }
-
@Override
public boolean isTraceEnabled() {
return isDebugEnabled();
@@ -86,9 +89,7 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
@Override
public void debug(String msg) {
- if (isDebugEnabled()) {
- logOut.logs(name, Level.Debug, msg);
- }
+ logs(Level.Debug, msg);
}
@Override
@@ -118,9 +119,7 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
@Override
public void info(String msg) {
- if (isInfoEnabled()) {
- logOut.logs(name, Level.Info, msg);
- }
+ logs(Level.Info, msg);
}
@Override
@@ -150,9 +149,7 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
@Override
public void warn(String msg) {
- if (isWarnEnabled()) {
- logOut.logs(name, Level.Warning, msg);
- }
+ logs(Level.Warning, msg);
}
@Override
@@ -182,9 +179,7 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
@Override
public void error(String msg) {
- if (isErrorEnabled()) {
- logOut.logs(name, Level.Error, msg);
- }
+ logs(Level.Error, msg);
}
@Override
@@ -212,21 +207,23 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
}
public Level getLevel() {
- return level;
+ return level.get();
}
public void setLevel(Level level) {
- this.level = level;
+ this.level.set(level);
}
public LogOut getLogOut() {
- return logOut;
+ return logOut.get();
}
public void setLogOut(LogOut logOut) {
- this.logOut = logOut;
- for (AsteriskScfLogger child : children.values()) {
- child.setLogOut(logOut);
+ this.logOut.set(logOut);
+ synchronized (children) {
+ for (AsteriskScfLogger child : children.values()) {
+ child.setLogOut(logOut);
+ }
}
}
@@ -235,7 +232,27 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
}
public Collection<AsteriskScfLogger> getChildren() {
- return children.values();
+ // synchronized copy is the best way to thread-safely return a list
+ // of the values.
+ synchronized (children) {
+ return new ArrayList<AsteriskScfLogger>(children.values());
+ }
+ }
+
+ private Level getEffectiveLevel() {
+ Level level = this.level.get();
+ if (level == null) {
+ return (parent == null) ? Level.Debug : parent.getEffectiveLevel();
+ } else {
+ return level;
+ }
+ }
+
+ private void logs(Level level, String msg) {
+ LogOut logOut = this.logOut.get();
+ if (logOut != null && isEnabledFor(level)) {
+ logOut.logs(name, level, msg);
+ }
}
private AsteriskScfLogger getChildLogger(final String fullName, String subName) {
@@ -255,22 +272,24 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
}
private boolean isEnabledFor(Level comparison) {
- return logOut != null && getEffectiveLevel().ordinal() <= comparison.ordinal();
+ return getEffectiveLevel().ordinal() <= comparison.ordinal();
}
private AsteriskScfLogger getOrCreateChild(String subName) {
assert (subName.indexOf('.') == -1);
- AsteriskScfLogger child = children.get(subName);
- if (child == null) {
- String childName;
- if (name.isEmpty()) {
- childName = subName;
- } else {
- childName = name + "." + subName;
+ synchronized (children) {
+ AsteriskScfLogger child = children.get(subName);
+ if (child == null) {
+ String childName;
+ if (name.isEmpty()) {
+ childName = subName;
+ } else {
+ childName = name + "." + subName;
+ }
+ child = new AsteriskScfLogger(childName, this, logOut.get());
+ children.put(subName, child);
}
- child = new AsteriskScfLogger(childName, this, logOut);
- children.put(subName, child);
+ return child;
}
- return child;
}
}
diff --git a/src/main/java/com/digium/asterisk/scf/jlogging/SystemLogOut.java b/src/main/java/com/digium/asterisk/scf/jlogging/PrintStreamLogOut.java
similarity index 88%
copy from src/main/java/com/digium/asterisk/scf/jlogging/SystemLogOut.java
copy to src/main/java/com/digium/asterisk/scf/jlogging/PrintStreamLogOut.java
index 91bb1cc..6f837c2 100644
--- a/src/main/java/com/digium/asterisk/scf/jlogging/SystemLogOut.java
+++ b/src/main/java/com/digium/asterisk/scf/jlogging/PrintStreamLogOut.java
@@ -20,14 +20,14 @@ import AsteriskSCF.System.Logging.Level;
import java.io.PrintStream;
-public class SystemLogOut implements LogOut {
+public class PrintStreamLogOut implements LogOut {
private PrintStream out;
- public SystemLogOut() {
+ public PrintStreamLogOut() {
this(System.out);
}
- public SystemLogOut(PrintStream out) {
+ public PrintStreamLogOut(PrintStream out) {
this.out = out;
}
diff --git a/src/test/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerTest.java b/src/test/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerTest.java
new file mode 100644
index 0000000..5be9d27
--- /dev/null
+++ b/src/test/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerTest.java
@@ -0,0 +1,50 @@
+/*
+ * Asterisk SCF - An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+package com.digium.asterisk.scf.jlogging;
+
+import org.jmock.Mockery;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+
+public class AsteriskScfLoggerTest {
+ private AsteriskScfLogger uut;
+ private Mockery context;
+
+ @Before
+ public void setUp() {
+ uut = new AsteriskScfLogger("");
+ context = new Mockery();
+ }
+
+ @After
+ public void tearDown() {
+ context.assertIsSatisfied();
+ }
+
+ @Test
+ public void testSetLogOut() {
+ AsteriskScfLogger foo = uut.getChildLogger("AsteriskSCF.Logger.Foo");
+ LogOut logOut = context.mock(LogOut.class);
+ uut.setLogOut(logOut);
+
+ assertThat(foo.getLogOut(), is(sameInstance(logOut)));
+ }
+}
diff --git a/src/test/java/com/digium/asterisk/scf/jlogging/IceIntegrationTest.java b/src/test/java/com/digium/asterisk/scf/jlogging/IceIntegrationTest.java
new file mode 100644
index 0000000..2271a28
--- /dev/null
+++ b/src/test/java/com/digium/asterisk/scf/jlogging/IceIntegrationTest.java
@@ -0,0 +1,103 @@
+/*
+ * Asterisk SCF - An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+package com.digium.asterisk.scf.jlogging;
+
+import AsteriskSCF.Core.Discovery.V1.ServiceLocator;
+import AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams;
+import AsteriskSCF.Core.Discovery.V1.ServiceNotFound;
+import AsteriskSCF.Core.Discovery.V1._ServiceLocatorDisp;
+import AsteriskSCF.System.Logging.Configuration;
+import AsteriskSCF.System.Logging.Level;
+import AsteriskSCF.System.Logging.LoggingServer;
+import AsteriskSCF.System.Logging._LoggingServerDisp;
+import Ice.Communicator;
+import Ice.Current;
+import Ice.ObjectAdapter;
+import Ice.ObjectPrx;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.junit.After;
+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;
+
+
+ @Before
+ public void setUp() {
+
+ context = new Mockery();
+ loggingServer = new MockableLoggingServer(context);
+ serviceLocator = new MockableServiceLocator(context);
+
+ communicator = Ice.Util.initialize();
+ adapter = communicator.createObjectAdapterWithEndpoints("adapter", "default");
+
+ 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?!?");
+ }
+ }});
+
+ uut = new AsteriskScfLoggerFactory();
+ uut.setAdapter(adapter);
+ }
+
+ @After
+ public void tearDown() {
+ communicator.shutdown();
+ communicator.waitForShutdown();
+ communicator.destroy();
+ }
+
+ @After
+ public void checkMockContext() {
+ context.assertIsSatisfied();
+ }
+
+ @Test
+ public void simpleGolden() {
+ context.checking(new Expectations() {{
+ one(loggingServer.getMock()).logs(with(is("")), with(is(Level.Debug)), with(is("debug")));
+ }});
+ uut.getLogger("").debug("debug");
+ }
+}
diff --git a/src/main/java/com/digium/asterisk/scf/jlogging/SystemLogOut.java b/src/test/java/com/digium/asterisk/scf/jlogging/MockableLoggingServer.java
similarity index 53%
rename from src/main/java/com/digium/asterisk/scf/jlogging/SystemLogOut.java
rename to src/test/java/com/digium/asterisk/scf/jlogging/MockableLoggingServer.java
index 91bb1cc..8a7b0c8 100644
--- a/src/main/java/com/digium/asterisk/scf/jlogging/SystemLogOut.java
+++ b/src/test/java/com/digium/asterisk/scf/jlogging/MockableLoggingServer.java
@@ -16,27 +16,31 @@
package com.digium.asterisk.scf.jlogging;
+import AsteriskSCF.System.Logging.Configuration;
import AsteriskSCF.System.Logging.Level;
+import AsteriskSCF.System.Logging.LoggingServer;
+import AsteriskSCF.System.Logging._LoggingServerDisp;
+import Ice.Current;
+import org.jmock.Mockery;
-import java.io.PrintStream;
+public class MockableLoggingServer extends _LoggingServerDisp {
+ private LoggingServer mock;
-public class SystemLogOut implements LogOut {
- private PrintStream out;
-
- public SystemLogOut() {
- this(System.out);
+ public MockableLoggingServer(Mockery context) {
+ mock = context.mock(LoggingServer.class);
}
- public SystemLogOut(PrintStream out) {
- this.out = out;
+ @Override
+ public void logs(String name, Level logLevel, String message, Current __current) {
+ mock.logs(name, logLevel, message);
}
@Override
- public void logs(String name, Level logLevel, String message) {
- message = message.trim();
- // synchronize so messages are serialized
- synchronized (this) {
- out.printf("%s:%s:%s\n", name, logLevel.name(), message);
- }
+ public Configuration getConfiguration(Current __current) {
+ return mock.getConfiguration();
+ }
+
+ public LoggingServer getMock() {
+ return mock;
}
}
diff --git a/src/test/java/com/digium/asterisk/scf/jlogging/MockableServiceLocator.java b/src/test/java/com/digium/asterisk/scf/jlogging/MockableServiceLocator.java
new file mode 100644
index 0000000..b73a1c0
--- /dev/null
+++ b/src/test/java/com/digium/asterisk/scf/jlogging/MockableServiceLocator.java
@@ -0,0 +1,47 @@
+/*
+ * Asterisk SCF - An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+package com.digium.asterisk.scf.jlogging;
+
+import AsteriskSCF.Core.Discovery.V1.ServiceLocator;
+import AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams;
+import AsteriskSCF.Core.Discovery.V1.ServiceNotFound;
+import AsteriskSCF.Core.Discovery.V1._ServiceLocatorDisp;
+import Ice.Current;
+import Ice.ObjectPrx;
+import org.jmock.Mockery;
+
+public class MockableServiceLocator extends _ServiceLocatorDisp {
+ private ServiceLocator mock;
+
+ public MockableServiceLocator(Mockery context) {
+ mock = context.mock(ServiceLocator.class);
+ }
+
+ @Override
+ public ObjectPrx locate(ServiceLocatorParams params, Current __current) throws ServiceNotFound {
+ return mock.locate(params);
+ }
+
+ @Override
+ public ObjectPrx[] locateAll(ServiceLocatorParams params, Current __current) throws ServiceNotFound {
+ return mock.locateAll(params);
+ }
+
+ public ServiceLocator getMock() {
+ return mock;
+ }
+}
diff --git a/src/test/java/com/digium/asterisk/scf/jlogging/Slf4jIntegrationTest.java b/src/test/java/com/digium/asterisk/scf/jlogging/Slf4jIntegrationTest.java
new file mode 100644
index 0000000..6e387c3
--- /dev/null
+++ b/src/test/java/com/digium/asterisk/scf/jlogging/Slf4jIntegrationTest.java
@@ -0,0 +1,55 @@
+/*
+ * Asterisk SCF - An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+package com.digium.asterisk.scf.jlogging;
+
+import AsteriskSCF.System.Logging.Level;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.impl.StaticLoggerBinder;
+
+public class Slf4jIntegrationTest {
+ private Mockery context;
+ private LogOut mockLogOut;
+
+ @Before
+ public void setUp() {
+ context = new Mockery();
+ mockLogOut = context.mock(LogOut.class);
+
+ StaticLoggerBinder binder = StaticLoggerBinder.getSingleton();
+ AsteriskScfLoggerFactory factory = (AsteriskScfLoggerFactory) binder.getLoggerFactory();
+ factory.getLogger("").setLogOut(mockLogOut);
+ }
+
+ @After
+ public void tearDown() {
+ context.assertIsSatisfied();
+ }
+ @Test
+ public void testConfig() {
+ context.checking(new Expectations(){{
+ one(mockLogOut).logs("AsteriskSCF.Logger", Level.Debug, "debug");
+ }});
+ Logger uut = LoggerFactory.getLogger("AsteriskSCF.Logger");
+ uut.debug("debug");
+ }
+}
commit f7f71823ebf04d1b90d1afcd99f6042e2ca68677
Author: David M. Lee <dlee at digium.com>
Date: Tue Nov 16 22:49:13 2010 -0600
Removing bogus test.
diff --git a/src/test/java/com/digium/asterisk/scf/jlogging/Slf4jTest.java b/src/test/java/com/digium/asterisk/scf/jlogging/Slf4jTest.java
deleted file mode 100644
index 3827377..0000000
--- a/src/test/java/com/digium/asterisk/scf/jlogging/Slf4jTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Asterisk SCF - An open-source communications framework.
- *
- * Copyright (C) 2010, Digium, Inc.
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk SCF project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE.txt file
- * at the top of the source tree.
- */
-
-package com.digium.asterisk.scf.jlogging;
-
-import Ice.Communicator;
-import Ice.ObjectAdapter;
-import Ice.Util;
-import org.junit.Before;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class Slf4jTest {
- Logger uut = LoggerFactory.getLogger("AsteriskSCF");
- Communicator communicator;
- ObjectAdapter adapter;
-
- @Before
- public void setUp() {
- communicator = Util.initialize();
-
- communicator.getProperties().setProperty("LocatorService.Proxy", "LocatorService:tcp -p 4411");
- communicator.getProperties().setProperty("TopicManager.Proxy", "AsteriskSCFIceStorm/TopicManager:default -p 10000");
-
-
- adapter = communicator.createObjectAdapterWithEndpoints("testAdapter", "default");
- AsteriskScfLoggerFactory realFactory =
- (AsteriskScfLoggerFactory) LoggerFactory.getILoggerFactory();
- realFactory.setAdapter(adapter);
- }
-
- @Test
- public void testGet() {
- uut.info("debug");
- }
-}
commit 4e10ec7257b4faac6c7f49d2d9ccd8ec505c7624
Author: David M. Lee <dlee at digium.com>
Date: Mon Nov 15 16:51:59 2010 -0600
Works, but very ugly.
diff --git a/jlogger.iml b/jlogger.iml
index 7caccfe..6845701 100644
--- a/jlogger.iml
+++ b/jlogger.iml
@@ -3,7 +3,6 @@
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
- <exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
@@ -15,6 +14,9 @@
<orderEntry type="library" name="Maven: com.zeroc:ice:3.4.1-digium" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.6.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.5" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: org.jmock:jmock:2.5.1" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.1" level="project" />
</component>
</module>
diff --git a/jlogger.ipr b/jlogger.ipr
index 7643df4..aa5700e 100644
--- a/jlogger.ipr
+++ b/jlogger.ipr
@@ -277,6 +277,39 @@
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.5/junit-4.5-sources.jar!/" />
</SOURCES>
</library>
+ <library name="Maven: org.jmock:jmock:2.5.1">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/jmock/jmock/2.5.1/jmock-2.5.1.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/org/jmock/jmock/2.5.1/jmock-2.5.1-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/jmock/jmock/2.5.1/jmock-2.5.1-sources.jar!/" />
+ </SOURCES>
+ </library>
+ <library name="Maven: org.hamcrest:hamcrest-core:1.1">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1-sources.jar!/" />
+ </SOURCES>
+ </library>
+ <library name="Maven: org.hamcrest:hamcrest-library:1.1">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-library/1.1/hamcrest-library-1.1.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-library/1.1/hamcrest-library-1.1-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-library/1.1/hamcrest-library-1.1-sources.jar!/" />
+ </SOURCES>
+ </library>
</component>
</project>
diff --git a/pom.xml b/pom.xml
index 0991e1d..2cc84f9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,6 +43,12 @@
<version>4.5</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock</artifactId>
+ <version>2.5.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java b/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java
index 2f4486e..065f64d 100644
--- a/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java
+++ b/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerFactory.java
@@ -16,10 +16,23 @@
package com.digium.asterisk.scf.jlogging;
-import AsteriskSCF.System.Logging.LoggingServerPrx;
+import AsteriskSCF.System.Logging.Configuration;
+import AsteriskSCF.System.Logging.ServerConfigurationTopic;
+import AsteriskSCF.System.Logging.SourceConfiguration;
+import AsteriskSCF.System.Logging._ServerConfigurationListenerDisp;
+import Ice.Communicator;
+import Ice.Current;
+import Ice.ObjectAdapter;
+import Ice.ObjectPrx;
+import IceStorm.TopicManagerPrx;
+import IceStorm.TopicManagerPrxHelper;
+import IceStorm.TopicPrx;
import org.slf4j.ILoggerFactory;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
public class AsteriskScfLoggerFactory implements ILoggerFactory {
@@ -46,4 +59,79 @@ public class AsteriskScfLoggerFactory implements ILoggerFactory {
}
return out;
}
+
+ public void setAdapter(ObjectAdapter adapter) {
+ IceLogger iceLogger = IceLogger.create(adapter);
+ root.setLogOut(iceLogger);
+
+ Communicator communicator = adapter.getCommunicator();
+
+ TopicManagerPrx topicManager = TopicManagerPrxHelper.checkedCast(
+ communicator.propertyToProxy("TopicManager.Proxy"));
+
+ try {
+ if (topicManager != null) {
+ TopicPrx topic = topicManager.retrieve(ServerConfigurationTopic.value);
+ IceConfigurator r = new IceConfigurator();
+ ObjectPrx proxy = adapter.addWithUUID(r).ice_oneway();
+
+ topic.subscribeAndGetPublisher(null, proxy);
+ adapter.activate();
+ return;
+ }
+ } catch (Exception e) {
+ System.err.println("Exception trying to register with Ice topic.");
+ e.printStackTrace(System.err);
+ }
+ System.err.println("Could not obtain proxy to TopicManager.");
+ }
+
+ public class IceConfigurator extends _ServerConfigurationListenerDisp {
+
+ @Override
+ public void configured(Configuration logConfiguration, Current __current) {
+ List<String> oldConfig = getLoggerNames();
+ Collections.sort(oldConfig);
+
+ List<SourceConfiguration> newConfig = Arrays.asList(logConfiguration.sourceSettings);
+ Collections.sort(newConfig, new Comparator<SourceConfiguration>() {
+ @Override
+ public int compare(SourceConfiguration lhs, SourceConfiguration rhs) {
+ return lhs.name.compareTo(rhs.name);
+ }
+ });
+
+ int oldIndex = 0;
+ int newIndex = 0;
+
+ while (oldIndex < oldConfig.size() || newIndex < newConfig.size()) {
+ int cmp;
+
+ if (newIndex >= newConfig.size()) {
+ // we ran out of new config; unset the rest of the old config
+ // new[end] < old
+ cmp = 1;
+ } else if (oldIndex >= oldConfig.size()) {
+ // we ran out of the old config; set rest of the new config
+ // new > old[end]
+ cmp = -1;
+ } else {
+ cmp = newConfig.get(newIndex).name.compareTo(oldConfig.get(oldIndex));
+ }
+
+ if (cmp < 0) {
+ getLogger(newConfig.get(newIndex).name).setLevel(newConfig.get(newIndex).logLevel);
+ ++newIndex;
+ } else if (cmp == 0) {
+ getLogger(newConfig.get(newIndex).name).setLevel(newConfig.get(newIndex).logLevel);
+ ++newIndex;
+ ++oldIndex;
+ } else /* if (cmp > 0) */ {
+ getLogger(oldConfig.get(oldIndex)).setLevel(null);
+ ++oldIndex;
+ }
+ }
+ }
+
+ }
}
diff --git a/src/main/java/com/digium/asterisk/scf/jlogging/IceConfigurator.java b/src/main/java/com/digium/asterisk/scf/jlogging/IceConfigurator.java
deleted file mode 100644
index 5ce2318..0000000
--- a/src/main/java/com/digium/asterisk/scf/jlogging/IceConfigurator.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Asterisk SCF - An open-source communications framework.
- *
- * Copyright (C) 2010, Digium, Inc.
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk SCF project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE.txt file
- * at the top of the source tree.
- */
-
-package com.digium.asterisk.scf.jlogging;
-
-import AsteriskSCF.System.Logging.Configuration;
-import AsteriskSCF.System.Logging._ServerConfigurationListenerDisp;
-import Ice.Current;
-
-import java.util.Collections;
-import java.util.List;
-
-public class IceConfigurator extends _ServerConfigurationListenerDisp {
- private AsteriskScfLoggerFactory factory;
-
- @Override
- public void configured(Configuration logConfiguration, Current __current) {
- List<String> oldConfig = factory.getLoggerNames();
- Collections.sort(oldConfig);
- }
-}
diff --git a/src/main/java/com/digium/asterisk/scf/jlogging/IceLogger.java b/src/main/java/com/digium/asterisk/scf/jlogging/IceLogger.java
index 20c211f..f0cc42a 100644
--- a/src/main/java/com/digium/asterisk/scf/jlogging/IceLogger.java
+++ b/src/main/java/com/digium/asterisk/scf/jlogging/IceLogger.java
@@ -16,23 +16,42 @@
package com.digium.asterisk.scf.jlogging;
+import AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams;
+import AsteriskSCF.Core.Discovery.V1.ServiceLocatorPrx;
+import AsteriskSCF.Core.Discovery.V1.ServiceLocatorPrxHelper;
+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.LoggingServer;
+import AsteriskSCF.System.Logging.LoggingServerGuid;
+import AsteriskSCF.System.Logging.LoggingServerPrx;
+import AsteriskSCF.System.Logging.LoggingServerPrxHelper;
+import Ice.Communicator;
+import Ice.Current;
+import Ice.ObjectAdapter;
+import Ice.ObjectPrx;
+import IceStorm.TopicManagerPrx;
+import IceStorm.TopicManagerPrxHelper;
+import IceStorm.TopicPrx;
import java.util.concurrent.atomic.AtomicReference;
public class IceLogger implements LogOut {
- private AtomicReference<LoggingServer> server;
+ private AtomicReference<LoggingServerPrx> server;
- public IceLogger(LoggingServer server) {
- this.server = new AtomicReference<LoggingServer>(server);
+ public IceLogger() {
+ this(null);
}
- public LoggingServer getServer() {
+ public IceLogger(LoggingServerPrx server) {
+ this.server = new AtomicReference<LoggingServerPrx>(server);
+ }
+
+ public LoggingServerPrx getServer() {
return server.get();
}
- public void setServer(LoggingServer server) {
+ public void setServer(LoggingServerPrx server) {
this.server.set(server);
}
@@ -43,7 +62,7 @@ public class IceLogger implements LogOut {
boolean logged = false;
try {
// avoid race condition with setServer(null) by using local var
- LoggingServer s = getServer();
+ LoggingServerPrx s = getServer();
if (s != null) {
s.logs(name, logLevel, message);
logged = true;
@@ -58,4 +77,122 @@ public class IceLogger implements LogOut {
System.out.printf("(no server) %s:%s:%s\n", name, logLevel.name(), message);
}
}
+
+ /**
+ * Constructs an IceLogger, as specified in the properties of the given
+ * adapter's communicator's properties.
+ * <p/>
+ * <ul> <li>LoggerServer.Proxy - connect directly to LoggerServer; don't use
+ * LocatorService</li> <li>LocatorService.Proxy - proxy string for
+ * LocatorService</li> <li>TopicManager.Proxy - proxy string for
+ * TopicManager. Only used when using the LocatorService</li> </ul>
+ *
+ * @param adapter ObjectAdapter to use for listening to the Discovery
+ * topic.
+ * @return Smart pointer to a new ConfiguredIceLogger. Will never return
+ * null.
+ */
+ public static IceLogger create(ObjectAdapter adapter) {
+ Communicator communicator = adapter.getCommunicator();
+
+ // LoggerServer directly specified
+ ObjectPrx server = communicator.propertyToProxy("LoggerServer.Proxy");
+ if (server != null) {
+ return new IceLogger(LoggingServerPrxHelper.checkedCast(server));
+ }
+
+ ServiceLocatorPrx locator = ServiceLocatorPrxHelper.uncheckedCast(
+ communicator.propertyToProxy("LocatorService.Proxy"));
+ if (locator == null) {
+ System.err.println("LocatorService.Proxy not set. Cannot find " + LoggingServerGuid.value);
+ }
+
+ IceLogger r = new IceLogger();
+ LocatorListener listener = r.createLocator(locator);
+
+ TopicManagerPrx topicManager = TopicManagerPrxHelper.uncheckedCast(
+ communicator.propertyToProxy("TopicManager.Proxy"));
+ try {
+ if (topicManager != null) {
+ ObjectPrx proxy = adapter.addWithUUID(listener).ice_oneway();
+ TopicPrx topic = topicManager.retrieve(TOPIC.value);
+ if (topic != null) {
+ topic.subscribeAndGetPublisher(null, proxy);
+ }
+ } else {
+ System.err.println("TopicManager.Proxy not set. Will not receive updates.");
+ }
+ listener.updateLoggerFromServiceLocator();
+ } catch (Exception e) {
+ System.err.println("Failed to subscribe to " + TOPIC.value);
+ e.printStackTrace(System.err);
+ }
+ return r;
+ }
+
+ private LocatorListener createLocator(ServiceLocatorPrx locator) {
+ return new LocatorListener(locator);
+ }
+
+ private class LocatorListener extends _EventsDisp {
+ private ServiceLocatorPrx locator;
+
+ public LocatorListener(ServiceLocatorPrx locator) {
+ this.locator = locator;
+ }
+
+ @Override
+ public void comparisonRegistered(String guid, Current __current) {
+ // no-op
+ }
+
+ @Override
+ public void comparisonUnregistered(String guid, Current __current) {
+ // no-op
+ }
+
+ @Override
+ public void serviceRegistered(String guid, Current __current) {
+ if (guid.equals(LoggingServerGuid.value)) {
+ updateLoggerFromServiceLocator();
+ }
+ }
+
+ @Override
+ public void serviceUnregistered(String guid, Current __current) {
+ if (guid.equals(LoggingServerGuid.value)) {
+ updateLoggerFromServiceLocator();
+ }
+ }
+
+ @Override
+ public void serviceSuspended(String guid, Current __current) {
+ if (guid.equals(LoggingServerGuid.value)) {
+ updateLoggerFromServiceLocator();
+ }
+ }
+
+ @Override
+ public void serviceUnsuspended(String guid, Current __current) {
+ if (guid.equals(LoggingServerGuid.value)) {
+ updateLoggerFromServiceLocator();
+ }
+ }
+
+ private void updateLoggerFromServiceLocator() {
+ if (locator != null) {
+ try {
+ ServiceLocatorParams locatorParams = new ServiceLocatorParams();
+ ObjectPrx serverObject = locator.locate(locatorParams);
+ if (serverObject != null) {
+ LoggingServerPrx server = LoggingServerPrxHelper.checkedCast(serverObject);
+ setServer(server);
+ }
+ } catch (ServiceNotFound serviceNotFound) {
+ // couldn't find the service
+ setServer(null);
+ }
+ }
+ }
+ }
}
diff --git a/src/main/java/org/slf4j/impl/StaticLoggerBinder.java b/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
index 724261f..3852cfa 100644
--- a/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
+++ b/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
@@ -21,10 +21,20 @@ import org.slf4j.ILoggerFactory;
import org.slf4j.spi.LoggerFactoryBinder;
public class StaticLoggerBinder implements LoggerFactoryBinder {
+ private static final StaticLoggerBinder INSTANCE = new StaticLoggerBinder();
+
+ public static StaticLoggerBinder getSingleton() {
+ return INSTANCE;
+ }
+
private final ILoggerFactory loggerFactory;
- // not final to avoid being optimized away
- public static String REQUESTED_API_VERSION = "1.6"; // final
+ /**
+ * Declare the version of the SLF4J API this implementation is compiled
+ * against. The value of this field is usually modified with each release.
+ */
+ // to avoid constant folding by the compiler, this field must *not* be final
+ public static String REQUESTED_API_VERSION = "1.6"; // !final
public StaticLoggerBinder() {
this.loggerFactory = new AsteriskScfLoggerFactory();
diff --git a/src/test/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerFactoryTest.java b/src/test/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerFactoryTest.java
index 78d1738..dfd7662 100644
--- a/src/test/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerFactoryTest.java
+++ b/src/test/java/com/digium/asterisk/scf/jlogging/AsteriskScfLoggerFactoryTest.java
@@ -17,12 +17,15 @@
package com.digium.asterisk.scf.jlogging;
import AsteriskSCF.System.Logging.Level;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.*;
public class AsteriskScfLoggerFactoryTest {
public AsteriskScfLoggerFactory uut;
@@ -30,13 +33,26 @@ public class AsteriskScfLoggerFactoryTest {
private AsteriskScfLogger asteriskScf;
private AsteriskScfLogger core;
+ private Mockery context;
+ private LogOut mockLogOut;
+
@Before
public void setUp() {
+ context = new Mockery();
+ mockLogOut = context.mock(LogOut.class);
+
uut = new AsteriskScfLoggerFactory();
+ uut.getLogger("").setLogOut(mockLogOut);
root = uut.getLogger("");
asteriskScf = uut.getLogger("AsteriskSCF");
core = uut.getLogger("AsteriskSCF.Core");
+
+ }
+
+ @After
+ public void tearDown() {
+ context.assertIsSatisfied();
}
@Test
@@ -69,4 +85,129 @@ public class AsteriskScfLoggerFactoryTest {
root.setLevel(Level.Debug);
assertThat(asteriskScf.isDebugEnabled(), is(true));
}
+
+ @Test
+ public void testOff() {
+ context.checking(new Expectations() {{
+ // nothing should be called
+ }});
+ root.setLevel(Level.Off);
+ root.trace("trace");
+ root.debug("debug");
+ root.info("info");
+ root.warn("warn");
+ root.error("error");
+ }
+
+ @Test
+ public void testDebug() {
+ context.checking(new Expectations() {{
+ one(mockLogOut).logs("", Level.Debug, "trace");
+ one(mockLogOut).logs("", Level.Debug, "debug");
+ one(mockLogOut).logs("", Level.Info, "info");
+ one(mockLogOut).logs("", Level.Warning, "warn");
+ one(mockLogOut).logs("", Level.Error, "error");
+ }});
+ root.setLevel(Level.Debug);
+ root.trace("trace");
+ root.debug("debug");
+ root.info("info");
+ root.warn("warn");
+ root.error("error");
+ }
+
+ @Test
+ public void testInfo() {
+ context.checking(new Expectations() {{
+ one(mockLogOut).logs("", Level.Info, "info");
+ one(mockLogOut).logs("", Level.Warning, "warn");
+ one(mockLogOut).logs("", Level.Error, "error");
+ }});
+ root.setLevel(Level.Info);
+ root.trace("trace");
+ root.debug("debug");
+ root.info("info");
+ root.warn("warn");
+ root.error("error");
+ }
+
+ @Test
+ public void testNotice() {
+ context.checking(new Expectations() {{
+ one(mockLogOut).logs("", Level.Warning, "warn");
+ one(mockLogOut).logs("", Level.Error, "error");
+ }});
+ root.setLevel(Level.Notice);
+ root.trace("trace");
+ root.debug("debug");
+ root.info("info");
+ root.warn("warn");
+ root.error("error");
+ }
+
+ @Test
+ public void testWarning() {
+ context.checking(new Expectations() {{
+ one(mockLogOut).logs("", Level.Warning, "warn");
+ one(mockLogOut).logs("", Level.Error, "error");
+ }});
+ root.setLevel(Level.Warning);
+ root.trace("trace");
+ root.debug("debug");
+ root.info("info");
+ root.warn("warn");
+ root.error("error");
+ }
+
+ @Test
+ public void testError() {
+ context.checking(new Expectations() {{
+ one(mockLogOut).logs("", Level.Error, "error");
+ }});
+ root.setLevel(Level.Error);
+ root.trace("trace");
+ root.debug("debug");
+ root.info("info");
+ root.warn("warn");
+ root.error("error");
+ }
+
+ @Test
+ public void testCritical() {
+ context.checking(new Expectations() {{
+ // slf4j doesn't log higher than error
+ }});
+ root.setLevel(Level.Critical);
+ root.trace("trace");
+ root.debug("debug");
+ root.info("info");
+ root.warn("warn");
+ root.error("error");
+ }
+
+ @Test
+ public void testAlert() {
+ context.checking(new Expectations() {{
+ // slf4j doesn't log higher than error
+ }});
+ root.setLevel(Level.Alert);
+ root.trace("trace");
+ root.debug("debug");
+ root.info("info");
+ root.warn("warn");
+ root.error("error");
+ }
+
+ @Test
+ public void testEmergency() {
+ context.checking(new Expectations() {{
+ // slf4j doesn't log higher than error
+ }});
+ root.setLevel(Level.Emergency);
+ root.trace("trace");
+ root.debug("debug");
+ root.info("info");
+ root.warn("warn");
+ root.error("error");
+ }
}
diff --git a/src/test/java/com/digium/asterisk/scf/jlogging/Slf4jTest.java b/src/test/java/com/digium/asterisk/scf/jlogging/Slf4jTest.java
new file mode 100644
index 0000000..3827377
--- /dev/null
+++ b/src/test/java/com/digium/asterisk/scf/jlogging/Slf4jTest.java
@@ -0,0 +1,50 @@
+/*
+ * Asterisk SCF - An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+package com.digium.asterisk.scf.jlogging;
+
+import Ice.Communicator;
+import Ice.ObjectAdapter;
+import Ice.Util;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Slf4jTest {
+ Logger uut = LoggerFactory.getLogger("AsteriskSCF");
+ Communicator communicator;
+ ObjectAdapter adapter;
+
+ @Before
+ public void setUp() {
+ communicator = Util.initialize();
+
+ communicator.getProperties().setProperty("LocatorService.Proxy", "LocatorService:tcp -p 4411");
+ communicator.getProperties().setProperty("TopicManager.Proxy", "AsteriskSCFIceStorm/TopicManager:default -p 10000");
+
+
+ adapter = communicator.createObjectAdapterWithEndpoints("testAdapter", "default");
+ AsteriskScfLoggerFactory realFactory =
+ (AsteriskScfLoggerFactory) LoggerFactory.getILoggerFactory();
+ realFactory.setAdapter(adapter);
+ }
+
+ @Test
+ public void testGet() {
+ uut.info("debug");
+ }
+}
commit e47328d7853bfc46a0a177ccd91620cb03e005f4
Author: David M. Lee <dlee at digium.com>
Date: Mon Nov 15 10:35:42 2010 -0600
Disable logging if we have nowhere to log it.
diff --git a/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLogger.java b/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLogger.java
index 299f76d..846cd12 100644
--- a/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLogger.java
+++ b/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLogger.java
@@ -255,7 +255,7 @@ public final class AsteriskScfLogger extends MarkerIgnoringBase {
}
private boolean isEnabledFor(Level comparison) {
- return getEffectiveLevel().ordinal() <= comparison.ordinal();
+ return logOut != null && getEffectiveLevel().ordinal() <= comparison.ordinal();
}
private AsteriskScfLogger getOrCreateChild(String subName) {
commit 0feac566a75fac8dd25fd2a8b697c08f392212e3
Author: David M. Lee <dlee at digium.com>
Date: Mon Nov 15 09:52:02 2010 -0600
Initial port.
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ed8f48c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+target
+*.iws
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..ff0499c
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,84 @@
+Asterisk SCF is distributed by Digium, Inc. (Digium) under the GNU
+General Public License version 2 (GPLv2) and is also available under
+alternative licenses negotiated directly with Digium. If you obtained
+Asterisk SCF under the GPLv2, then those terms apply to all programs
+you distribute that communicate using the Asterisk SCF object
+interfaces (APIs) on objects provided by Asterisk SCF's components, as
+defined below. A copy of the GPLv2 is included in the Asterisk SCF
+source tree in the file COPYING.txt.
+
+Asterisk SCF is a collection of programs that communicate with each
+other over defined APIs. This communication can occur within a single
+process (if two programs are loaded into a suitable container),
+between processes on a single machine, between processes on different
+machines, or some combination. In addition, these APIs are usable
+across a number of platforms and also across a variety of programming
+languages, many of which are interpreted (scripting)
+languages. Because of this flexibility and the possible ambiguity in
+interpretation of the provisions of the GPLv2 as they apply to
+Asterisk SCF, Digium makes the following statement:
+
+ It is Digium's interpretation that because the Asterisk SCF APIs,
+ by definition, expose direct, and indirect, complex remote, and
+ non-remote, function calls on objects provided by Asterisk SCF's
+ programs, that usage of these APIs between the program hosting the
+ object(s) and the program accessing the object(s) creates a
+ derivative work that must be covered wholly by GPLv2, even if the
+ mechanism used to invoke the function calls employs a
+ cross-process or network connection. As a result, any program that
+ employs the Asterisk SCF APIs to perform its intended functions,
+ and would not be able to perform those intended functions without
+ using these APIs to communicate with Asterisk SCF programs, or
+ derivatives of Asterisk SCF programs, is subject to the terms of
+ the GPLv2 when it is distributed, unless the distributor of the
+ program has obtained explicit written permission from Digium to
+ distribute it under a different license.
+
+Digium is able to grant, at its sole discretion, permission for
+companies, individuals or organizations to distribute programs that
+use the Asterisk SCF APIs under open source or proprietary
+terms. Digium is able to do this because all components of the
+Asterisk SCF package are either copyrighted by Digium, because Digium
+has been granted a sufficient license by the component's copyright
+holder(s), or some combination thereof.
+
+Digium grants specific permission for anyone to distribute programs
+that use the Asterisk SCF APIs and also use the OpenSSL toolkit, Ice
+(Internet Communication Engine) from ZeroC and/or the UW IMAP toolkit
+("Open Source Exceptions"), even though the terms of the GPLv2 do not
+allow such distribution. This permission only extends to distributions
+that properly acknowledge and comply with the terms of the licenses on
+the Open Source Exceptions that are used in addition to the terms of
+the GPLv2.
+
+If you wish to use Asterisk SCF code in other GPLv2 programs, there is
+no requirement that you provide the same permissions for these Open
+Source Exceptions to recipients of your programs (although if you have
+written a program for Asterisk SCF, Digium would strongly encourage
+you to grant the same permissions granted by Digium).
+
+The 'Ice' and 'ZeroC' names are trademarks of ZeroC, Inc.
+
+The "Asterisk SCF" name and logos are trademarks owned by Digium and
+use of them is subject to Digium's trademark licensing policies. If
+you wish to use these trademarks for purposes other than unmodified
+redistribution of Asterisk SCF source code obtained from Digium, you
+should contact Digium's licensing department to determine the
+necessary steps you must take. For more information on this policy,
+please read:
+
+http://www.digium.com/en/company/profile/trademarkpolicy.php
+
+If you have any questions regarding our licensing policy, please contact us:
+
++1.877.344.4861 (via telephone in the USA)
++1.256.428.6000 (via telephone outside the USA)
++1.256.864.0464 (via FAX inside or outside the USA)
+IAX2/pbx.digium.com (via IAX2)
+sip:6000 at digium.com (via SIP)
+licensing at digium.com (via email)
+
+Digium, Inc.
+445 Jan Davis Drive NW
+Huntsville, AL 35806
+USA
diff --git a/jlogger.iml b/jlogger.iml
new file mode 100644
index 0000000..7caccfe
--- /dev/null
+++ b/jlogger.iml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/target/classes" />
+ <output-test url="file://$MODULE_DIR$/target/test-classes" />
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/target" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="Maven: com.digium.asteriskscf:api:0.0.1-SNAPSHOT" level="project" />
+ <orderEntry type="library" name="Maven: com.zeroc:ice:3.4.1-digium" level="project" />
+ <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.6.1" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.5" level="project" />
+ </component>
+</module>
+
diff --git a/jlogger.ipr b/jlogger.ipr
new file mode 100644
index 0000000..7643df4
--- /dev/null
+++ b/jlogger.ipr
@@ -0,0 +1,282 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="AntConfiguration">
+ <defaultAnt bundledAnt="true" />
+ </component>
+ <component name="CompilerConfiguration">
+ <option name="DEFAULT_COMPILER" value="Javac" />
+ <resourceExtensions>
+ <entry name=".+\.(properties|xml|html|dtd|tld)" />
+ <entry name=".+\.(gif|png|jpeg|jpg)" />
+ </resourceExtensions>
+ <wildcardResourcePatterns>
+ <entry name="?*.properties" />
+ <entry name="?*.xml" />
+ <entry name="?*.gif" />
+ <entry name="?*.png" />
+ <entry name="?*.jpeg" />
+ <entry name="?*.jpg" />
+ <entry name="?*.html" />
+ <entry name="?*.dtd" />
+ <entry name="?*.tld" />
+ <entry name="?*.ftl" />
+ </wildcardResourcePatterns>
+ <annotationProcessing enabled="false" useClasspath="true" />
+ </component>
+ <component name="CopyrightManager" default="ast-scf-open">
+ <copyright>
+ <option name="notice" value="Asterisk SCF - An open-source communications framework. Copyright (C) &#36;today.year, Digium, Inc. See http://www.asterisk.org for more information about the Asterisk SCF project. Please do not directly contact any of the maintainers of this project for assistance; the project provides a web site, mailing lists and IRC channels for your use. This program is free software, distributed under the terms of the GNU General Public License Version 2. See the LICENSE.txt file at the top of the source tree." />
+ <option name="keyword" value="Copyright" />
+ <option name="allowReplaceKeyword" value="Asterisk SCF" />
+ <option name="myName" value="ast-scf-open" />
+ <option name="myLocal" value="true" />
+ </copyright>
+ <module2copyright />
+ </component>
+ <component name="CppTools.Loader" reportImplicitCastToBool="false" reportNameReferencedOnce="false" version="3" compilerSelect="AUTO" />
+ <component name="DependencyValidationManager">
+ <option name="SKIP_IMPORT_STATEMENTS" value="false" />
+ </component>
+ <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
+ <component name="InspectionProjectProfileManager">
+ <profiles>
+ <profile version="1.0" is_locked="false">
+ <option name="myName" value="Project Default" />
+ <option name="myLocal" value="false" />
+ <inspection_tool class="Fix shebang" enabled="true" level="WARNING" enabled_by_default="true">/bin/sh#/bin/bash</inspection_tool>
+ <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
+ <option name="processCode" value="true" />
+ <option name="processLiterals" value="true" />
+ <option name="processComments" value="true" />
+ </inspection_tool>
+ <inspection_tool class="UnusedDeclaration" enabled="false" level="WARNING" enabled_by_default="false">
+ <option name="ADD_MAINS_TO_ENTRIES" value="true" />
+ <option name="ADD_APPLET_TO_ENTRIES" value="true" />
+ <option name="ADD_SERVLET_TO_ENTRIES" value="true" />
+ <option name="ADD_NONJAVA_TO_ENTRIES" value="true" />
+ <option name="ADDITIONAL_ANNOTATIONS">
+ <value>
+ <list size="1">
+ <item index="0" class="java.lang.String" itemvalue="javax.ws.rs.*" />
+ </list>
+ </value>
+ </option>
+ <option name="ADD_TESTNG_TO_ENTRIES" value="true" />
+ <option name="ADD_JUNIT_TO_ENTRIES" value="true" />
+ </inspection_tool>
+ </profile>
+ </profiles>
+ <option name="PROJECT_PROFILE" value="Project Default" />
+ <option name="USE_PROJECT_PROFILE" value="true" />
+ <version value="1.0" />
+ </component>
+ <component name="JavacSettings">
+ <option name="ADDITIONAL_OPTIONS_STRING" value="-target 1.6" />
+ </component>
+ <component name="JavadocGenerationManager">
+ <option name="OUTPUT_DIRECTORY" />
+ <option name="OPTION_SCOPE" value="protected" />
+ <option name="OPTION_HIERARCHY" value="true" />
+ <option name="OPTION_NAVIGATOR" value="true" />
+ <option name="OPTION_INDEX" value="true" />
+ <option name="OPTION_SEPARATE_INDEX" value="true" />
+ <option name="OPTION_DOCUMENT_TAG_USE" value="false" />
+ <option name="OPTION_DOCUMENT_TAG_AUTHOR" value="false" />
+ <option name="OPTION_DOCUMENT_TAG_VERSION" value="false" />
+ <option name="OPTION_DOCUMENT_TAG_DEPRECATED" value="true" />
+ <option name="OPTION_DEPRECATED_LIST" value="true" />
+ <option name="OTHER_OPTIONS" value="" />
+ <option name="HEAP_SIZE" />
+ <option name="LOCALE" />
+ <option name="OPEN_IN_BROWSER" value="true" />
+ </component>
+ <component name="MavenProjectsManager">
+ <option name="originalFiles">
+ <list>
+ <option value="$PROJECT_DIR$/pom.xml" />
+ </list>
+ </option>
+ </component>
+ <component name="Palette2">
+ <group name="Swing">
+ <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
+ <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
+ </item>
+ <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
+ <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
+ </item>
+ <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
+ <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
+ </item>
+ <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
+ <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
+ </item>
+ <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
+ <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
+ <initial-values>
+ <property name="text" value="Button" />
+ </initial-values>
+ </item>
+ <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
+ <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+ <initial-values>
+ <property name="text" value="RadioButton" />
+ </initial-values>
+ </item>
+ <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
+ <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+ <initial-values>
+ <property name="text" value="CheckBox" />
+ </initial-values>
+ </item>
+ <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
+ <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
+ <initial-values>
+ <property name="text" value="Label" />
+ </initial-values>
+ </item>
+ <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+ <preferred-size width="150" height="-1" />
+ </default-constraints>
+ </item>
+ <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+ <preferred-size width="150" height="-1" />
+ </default-constraints>
+ </item>
+ <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+ <preferred-size width="150" height="-1" />
+ </default-constraints>
+ </item>
+ <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+ <preferred-size width="150" height="50" />
+ </default-constraints>
+ </item>
+ <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+ <preferred-size width="150" height="50" />
+ </default-constraints>
+ </item>
+ <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+ <preferred-size width="150" height="50" />
+ </default-constraints>
+ </item>
+ <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
+ <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
+ </item>
+ <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+ <preferred-size width="150" height="50" />
+ </default-constraints>
+ </item>
+ <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
+ <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
+ <preferred-size width="150" height="50" />
+ </default-constraints>
+ </item>
+ <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+ <preferred-size width="150" height="50" />
+ </default-constraints>
+ </item>
+ <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
+ <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+ <preferred-size width="200" height="200" />
+ </default-constraints>
+ </item>
+ <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
+ <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+ <preferred-size width="200" height="200" />
+ </default-constraints>
+ </item>
+ <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+ </item>
+ <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+ </item>
+ <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
+ <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
+ </item>
+ <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
+ </item>
+ <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
+ <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
+ <preferred-size width="-1" height="20" />
+ </default-constraints>
+ </item>
+ <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
+ <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
+ </item>
+ <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
+ <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
+ </item>
+ </group>
+ </component>
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/jlogger.iml" filepath="$PROJECT_DIR$/jlogger.iml" />
+ </modules>
+ </component>
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
+ <output url="file://$PROJECT_DIR$/classes" />
+ </component>
+ <component name="SvnBranchConfigurationManager">
+ <option name="mySupportsUserInfoFilter" value="true" />
+ </component>
+ <component name="VcsDirectoryMappings">
+ <mapping directory="" vcs="Git" />
+ </component>
+ <component name="libraryTable">
+ <library name="Maven: com.digium.asteriskscf:api:0.0.1-SNAPSHOT">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/digium/asteriskscf/api/0.0.1-SNAPSHOT/api-0.0.1-SNAPSHOT.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/com/digium/asteriskscf/api/0.0.1-SNAPSHOT/api-0.0.1-SNAPSHOT-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/digium/asteriskscf/api/0.0.1-SNAPSHOT/api-0.0.1-SNAPSHOT-sources.jar!/" />
+ </SOURCES>
+ </library>
+ <library name="Maven: com.zeroc:ice:3.4.1-digium">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/zeroc/ice/3.4.1-digium/ice-3.4.1-digium.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/com/zeroc/ice/3.4.1-digium/ice-3.4.1-digium-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/zeroc/ice/3.4.1-digium/ice-3.4.1-digium-sources.jar!/" />
+ </SOURCES>
+ </library>
+ <library name="Maven: org.slf4j:slf4j-api:1.6.1">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1-sources.jar!/" />
+ </SOURCES>
+ </library>
+ <library name="Maven: junit:junit:4.5">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.5/junit-4.5.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.5/junit-4.5-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.5/junit-4.5-sources.jar!/" />
+ </SOURCES>
+ </library>
+ </component>
+</project>
+
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..0991e1d
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,76 @@
+<!--
+ ~ Asterisk SCF - An open-source communications framework.
+ ~
+ ~ Copyright (C) 2010, Digium, Inc.
+ ~
+ ~ See http://www.asterisk.org for more information about
+ ~ the Asterisk SCF project. Please do not directly contact
+ ~ any of the maintainers of this project for assistance;
+ ~ the project provides a web site, mailing lists and IRC
+ ~ channels for your use.
+ ~
+ ~ This program is free software, distributed under the terms of
+ ~ the GNU General Public License Version 2. See the LICENSE.txt file
+ ~ at the top of the source tree.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.digium.asteriskscf</groupId>
+ <artifactId>jlogger-1.6</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>jrouting</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.digium.asteriskscf</groupId>
+ <artifactId>api</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.6.1</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.5</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>${java.version}</source>
+ <target>${java.version}</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ <version>2.4</version>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <java.version>1.6</java.version>
+ </properties>
+</project>
diff --git a/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLogger.java b/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLogger.java
new file mode 100644
index 0000000..299f76d
--- /dev/null
+++ b/src/main/java/com/digium/asterisk/scf/jlogging/AsteriskScfLogger.java
@@ -0,0 +1,276 @@
+/*
+ * Asterisk SCF - An open-source communications framework.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+package com.digium.asterisk.scf.jlogging;
+
+import AsteriskSCF.System.Logging.Level;
+import org.slf4j.helpers.MarkerIgnoringBase;
+import org.slf4j.helpers.MessageFormatter;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+public final class AsteriskScfLogger extends MarkerIgnoringBase {
+ private AsteriskScfLogger parent = null;
+ private Map<String, AsteriskScfLogger> children = new HashMap<String, AsteriskScfLogger>();
+ private Level level = null;
+
+ private LogOut logOut;
+
+ public AsteriskScfLogger(String name, AsteriskScfLogger parent, LogOut logOut) {
+ this.name = name;
+ this.parent = parent;
+ this.logOut = logOut;
+ }
+
+ public AsteriskScfLogger(String name) {
+ this(name, null, null);
+ }
+
+ private Level getEffectiveLevel() {
+ if (level == null) {
+ return (parent == null) ? Level.Debug : parent.getEffectiveLevel();
+ } else {
+ return level;
+ }
+ }
+
+ @Override
+ public boolean isTraceEnabled() {
+ return isDebugEnabled();
+ }
+
+ @Override
+ public void trace(String msg) {
+ debug(msg);
+ }
+
+ @Override
+ public void trace(String format, Object arg) {
+ debug(format, arg);
+ }
+
+ @Override
+ public void trace(String format, Object arg1, Object arg2) {
+ debug(format, arg1, arg2);
+ }
+
+ @Override
+ public void trace(String format, Object[] argArray) {
+ debug(format, argArray);
+ }
+
+ @Override
+ public void trace(String msg, Throwable t) {
+ debug(msg, t);
+ }
+
+ @Override
+ public boolean isDebugEnabled() {
+ return isEnabledFor(Level.Debug);
+ }
+
+ @Override
+ public void debug(String msg) {
+ if (isDebugEnabled()) {
+ logOut.logs(name, Level.Debug, msg);
+ }
+ }
+
+ @Override
+ public void debug(String format, Object arg) {
+ debug(MessageFormatter.format(format, arg).getMessage());
+ }
+
+ @Override
+ public void debug(String format, Object arg1, Object arg2) {
+ debug(MessageFormatter.format(format, arg1, arg2).getMessage());
+ }
+
+ @Override
+ public void debug(String format, Object[] argArray) {
+ debug(MessageFormatter.format(format, argArray).getMessage());
+ }
+
+ @Override
+ public void debug(String msg, Throwable t) {
+ debug(msg + ": " + t.getMessage());
+ }
+
+ @Override
+ public boolean isInfoEnabled() {
+ return isEnabledFor(Level.Info);
+ }
+
+ @Override
+ public void info(String msg) {
+ if (isInfoEnabled()) {
... 607 lines suppressed ...
--
team/dlee/jlogger.git
More information about the asterisk-scf-commits
mailing list