logback-dev
Threads by month
- ----- 2025 -----
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
January 2007
- 6 participants
- 258 discussions
Online report : http://localhost:8090/continuum/servlet/continuum/target/ProjectBuild.vm/vi…
Build statistics:
State: Failed
Previous State: Failed
Started at: Fri, 12 Jan 2007 16:00:24 +0100
Finished at: Fri, 12 Jan 2007 16:00:28 +0100
Total time: 4s
Build Trigger: Schedule
Exit code: 1
Building machine hostname: pixie
Operating system : Linux(unknown)
Java version : 1.5.0_08(Sun Microsystems Inc.)
Changes
src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTestApp.java
src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTestApp.java
src/main/java/ch/qos/logback/classic/net/JMSQueueSink.java
src/main/java/ch/qos/logback/classic/net/JMSTopicSink.java
****************************************************************************
Output:
****************************************************************************
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Logback Classic Module
[INFO] task-segment: [clean, install]
[INFO] ----------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /opt/continuum-1.0.3/apps/continuum/working-directory/46/target
[INFO] Deleting directory /opt/continuum-1.0.3/apps/continuum/working-directory/46/target/classes
[INFO] Deleting directory /opt/continuum-1.0.3/apps/continuum/working-directory/46/target/test-classes
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
Downloading: http://repo1.maven.org/maven2/javax/jms/jms/1.1/jms-1.1.jar
[WARNING] Unable to get resource from repository central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) javax.jms:jms:jar:1.1
Try downloading the file manually from:
http://java.sun.com/products/jms/docs.html
Then, install it using the command:
mvn install:install-file -DgroupId=javax.jms -DartifactId=jms \
-Dversion=1.1 -Dpackaging=jar -Dfile=/path/to/file
Path to dependency:
1) ch.qos.logback:logback-classic:jar:0.8-SNAPSHOT
2) javax.jms:jms:jar:1.1
----------
1 required artifact is missing.
for artifact:
ch.qos.logback:logback-classic:jar:0.8-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Fri Jan 12 16:00:28 CET 2007
[INFO] Final Memory: 11M/83M
[INFO] ------------------------------------------------------------------------
****************************************************************************
1
0

svn commit: r1204 - in logback/trunk/logback-classic/src: main/java/ch/qos/logback/classic/net test/java/ch/qos/logback/classic/net
by noreply.seb@qos.ch 12 Jan '07
by noreply.seb@qos.ch 12 Jan '07
12 Jan '07
Author: seb
Date: Fri Jan 12 15:57:00 2007
New Revision: 1204
Added:
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTestApp.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTestApp.java
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueSink.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicSink.java
Log:
JMS*Appender test apps are back for performance testing
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueSink.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueSink.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueSink.java Fri Jan 12 15:57:00 2007
@@ -45,20 +45,20 @@
private Logger logger = (Logger)LoggerFactory.getLogger(JMSTopicSink.class);
static public void main(String[] args) throws Exception {
- if (args.length != 4) {
+ if (args.length != 2) {
usage("Wrong number of arguments.");
}
String qcfBindingName = args[0];
String queueBindingName = args[1];
- String username = args[2];
- String password = args[3];
+// String username = args[2];
+// String password = args[3];
LoggerContext loggerContext = (LoggerContext) LoggerFactory
.getILoggerFactory();
ContextInitializer.autoConfig(loggerContext);
- new JMSQueueSink(qcfBindingName, queueBindingName, username, password);
+ new JMSQueueSink(qcfBindingName, queueBindingName, null, null);
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
// Loop until the word "exit" is typed
@@ -138,7 +138,7 @@
System.err
.println("Usage: java "
+ JMSTopicSink.class.getName()
- + " QueueConnectionFactoryBindingName QueueBindingName username password");
+ + " QueueConnectionFactoryBindingName QueueBindingName");
System.exit(1);
}
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicSink.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicSink.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicSink.java Fri Jan 12 15:57:00 2007
@@ -45,20 +45,20 @@
private Logger logger = (Logger)LoggerFactory.getLogger(JMSTopicSink.class);
static public void main(String[] args) throws Exception {
- if (args.length != 4) {
+ if (args.length != 2) {
usage("Wrong number of arguments.");
}
String tcfBindingName = args[0];
String topicBindingName = args[1];
- String username = args[2];
- String password = args[3];
+// String username = args[2];
+// String password = args[3];
LoggerContext loggerContext = (LoggerContext) LoggerFactory
.getILoggerFactory();
ContextInitializer.autoConfig(loggerContext);
- new JMSTopicSink(tcfBindingName, topicBindingName, username, password);
+ new JMSTopicSink(tcfBindingName, topicBindingName, null, null);
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
// Loop until the word "exit" is typed
@@ -109,7 +109,6 @@
public void onMessage(javax.jms.Message message) {
LoggingEvent event;
- System.out.println("xxxx onMessage called");
try {
if (message instanceof ObjectMessage) {
ObjectMessage objectMessage = (ObjectMessage) message;
@@ -139,7 +138,7 @@
System.err
.println("Usage: java "
+ JMSTopicSink.class.getName()
- + " TopicConnectionFactoryBindingName TopicBindingName username password");
+ + " TopicConnectionFactoryBindingName TopicBindingName");
System.exit(1);
}
}
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTestApp.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTestApp.java Fri Jan 12 15:57:00 2007
@@ -0,0 +1,48 @@
+package ch.qos.logback.classic.net;
+
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.core.util.StatusPrinter;
+
+public class JMSQueueAppenderTestApp {
+
+ public static void main(String[] args) {
+ Logger logger = (Logger)LoggerFactory.getLogger(JMSTopicAppenderTestApp.class);
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+ lc.shutdownAndReset();
+
+ JMSQueueAppender appender = new JMSQueueAppender();
+ appender.setContext(lc);
+ appender.setName("jmsQueue");
+ appender.setInitialContextFactoryName("org.apache.activemq.jndi.ActiveMQInitialContextFactory");
+ //appender.setPassword("");
+ appender.setProviderURL("tcp://localhost:61616");
+ //appender.setSecurityCredentials("");
+ //appender.setSecurityPrincipalName("");
+ appender.setQueueBindingName("MyQueue");
+ appender.setQueueConnectionFactoryBindingName("ConnectionFactory");
+ //appender.setURLPkgPrefixes("");
+ //appender.setUserName("");
+
+ appender.start();
+ logger.addAppender(appender);
+
+ //JIT
+ for (int i = 0; i < 10000; i++) {
+ logger.debug("** Hello world. n=" + i);
+ }
+
+ long before = System.nanoTime();
+ for (int i = 0; i < 10000; i++) {
+ logger.debug("** Hello world. n=" + i);
+ }
+ long after = System.nanoTime();
+
+ System.out.println("Time per logs for 10'000 logs: " + (after-before)/10000);
+
+ StatusPrinter.print(lc.getStatusManager());
+ }
+
+}
\ No newline at end of file
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTestApp.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTestApp.java Fri Jan 12 15:57:00 2007
@@ -0,0 +1,49 @@
+package ch.qos.logback.classic.net;
+
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.core.util.StatusPrinter;
+
+public class JMSTopicAppenderTestApp {
+
+ public static void main(String[] args) {
+ Logger logger = (Logger)LoggerFactory.getLogger(JMSTopicAppenderTestApp.class);
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+ lc.shutdownAndReset();
+
+ JMSTopicAppender appender = new JMSTopicAppender();
+ appender.setContext(lc);
+ appender.setName("jmsTopic");
+ appender.setInitialContextFactoryName("org.apache.activemq.jndi.ActiveMQInitialContextFactory");
+ //appender.setPassword("");
+ appender.setProviderURL("tcp://localhost:61616");
+ //appender.setSecurityCredentials("");
+ //appender.setSecurityPrincipalName("");
+ appender.setTopicBindingName("MyTopic");
+ appender.setTopicConnectionFactoryBindingName("ConnectionFactory");
+ //appender.setURLPkgPrefixes("");
+ //appender.setUserName("");
+
+ appender.start();
+ logger.addAppender(appender);
+
+
+ //JIT
+ for (int i = 0; i < 10000; i++) {
+ logger.debug("** Hello world. n=" + i);
+ }
+
+ long before = System.nanoTime();
+ for (int i = 0; i < 10000; i++) {
+ logger.debug("** Hello world. n=" + i);
+ }
+ long after = System.nanoTime();
+
+ System.out.println("Time per logs for 10'000 logs: " + (after-before)/10000);
+
+ StatusPrinter.print(lc.getStatusManager());
+ }
+
+}
\ No newline at end of file
1
0

12 Jan '07
Author: seb
Date: Fri Jan 12 13:51:12 2007
New Revision: 1202
Modified:
logback/trunk/logback-site/src/site/fml/faq.fml
Log:
added questions on JCL interception
Modified: logback/trunk/logback-site/src/site/fml/faq.fml
==============================================================================
--- logback/trunk/logback-site/src/site/fml/faq.fml (original)
+++ logback/trunk/logback-site/src/site/fml/faq.fml Fri Jan 12 13:51:12 2007
@@ -15,6 +15,11 @@
</question>
<answer>
+ <p>
+ The Jetty application server uses SLF4J for its internal
+ logging. Here are the required steps to install logback as
+ SLF4J's underlaying implementation.
+ </p>
<p>
A few jars must be present in the
<em>JETTY_HOME/lib</em>
@@ -30,15 +35,14 @@
<p>
Logback's own jars must also be present, namely
<em>logback-core-VERSION.jar</em> and
- <em>logback-classic-VERSION.jar</em> .
+ <em>logback-classic-VERSION.jar</em>.
</p>
<p>
To configure logback-classic, a file called
- <em>logback.xml</em> should be placed at the root
- directory of Jetty, that is the <em>JETTY_HOME</em>
- directory or in the <em>JETTY_HOME/resources</em> directory,
- depending on your classpath settings. You can find configuration samples in the
+ <em>logback.xml</em> should be placed in the
+ <em>JETTY_HOME/resources</em> directory.
+ You can find configuration samples in the
<em>examples/src/chapter4/conf/</em> directory, in the
distribution of logback.
</p>
@@ -68,6 +72,75 @@
</faq>
+ <faq id="intercept_calls_tomcat">
+
+ <question>
+ How can I intercept JCL calls in Tomcat?
+ </question>
+
+ <answer>
+ <p>
+ When a dependency of your webapp logs using Jakarta Commons Logging
+ (for example Struts), you can intercept these calls and redirect them to logback.
+ </p>
+ <p>
+ This can be done by using <em>jcl104-over-slf4j.jar</em>, a module
+ that is shipped with <a href="http://www.slf4j.org">SLF4J</a>.
+ </p>
+ <p>
+ If you have only one webapp, its <em>WEB-INF/lib</em> directory should already
+ contain the logback jars, namely <em>logback-core-VERSION.jar</em>,
+ <em>logback-classic-VERSION.jar</em> and <em>slf4j-api-VERSION.jar</em>.
+ A logback configuration file, named
+ <em>logback.xml</em> should be placed in the <em>WEB-INF/classes/</em>
+ directory.
+ </p>
+ <p>
+ You now need to add <code>jcl104-over-slf4j.jar</code>
+ to your <em>WEB-INF/lib</em> directory and remove
+ <code>commons-logging-1.0.4.jar</code>. The logging that used to
+ be directed to JCL should now be handled by logback.
+ </p>
+
+ <p>
+ In case several webapps share the logback jars, you might place the
+ previously mentionned jars in the <em>common/lib/</em> directory of
+ your Tomcat installation. The <em>logback.xml</em> file should then
+ be placed in <em>common/classes</em>.
+ </p>
+ </answer>
+ </faq>
+
+ <faq id="intercept_calls_jetty">
+
+ <question>
+ How can I intercept JCL calls in Jetty ?
+ </question>
+
+ <answer>
+ <p>
+ Using logback as the logging implementation of choice for frameworks
+ depending on JCL can also be done in Jetty.
+ </p>
+ <p>
+ In case you have only one webapp, the required steps are exactly the same
+ as <a href="#intercept_calls_tomcat">those needed in Tomcat</a>.
+ </p>
+ <p>
+ In case several webapps share the logback jars, you might place the
+ necessary jars in the <em>lib/</em> directory of
+ your Jetty installation. The <em>logback.xml</em> file should then
+ be placed in the <em>resources/</em> directory.
+ </p>
+ <p>
+ However, due to <a href="http://docs.codehaus.org/display/JETTY/Classloading">
+ Jetty's internal Classloading mechanism</a>, the <em>logback-classic-VERSION.jar</em>
+ and <em>slf4j-api-VERSION.jar</em> files need to be in your webapps, too. They
+ should be placed in the <em>WEB-INF/lib/</em> directory of your webapps.
+ </p>
+ </answer>
+ </faq>
+
</part>
</faqs>
</body>
1
0
Author: seb
Date: Fri Jan 12 11:09:14 2007
New Revision: 1201
Modified:
logback/trunk/pom.xml
Log:
only testing
Modified: logback/trunk/pom.xml
==============================================================================
--- logback/trunk/pom.xml (original)
+++ logback/trunk/pom.xml Fri Jan 12 11:09:14 2007
@@ -16,7 +16,7 @@
<url>http://www.qos.ch</url>
</organization>
<inceptionYear>2005</inceptionYear>
-
+
<modules>
<module>logback-core</module>
<module>logback-classic</module>
1
0

svn commit: r1200 - logback/trunk/logback-site/src/site/xdocTemplates
by noreply.seb@qos.ch 11 Jan '07
by noreply.seb@qos.ch 11 Jan '07
11 Jan '07
Author: seb
Date: Thu Jan 11 18:56:59 2007
New Revision: 1200
Modified:
logback/trunk/logback-site/src/site/xdocTemplates/shortIntro.xml
Log:
updated short intro's configuration section
Modified: logback/trunk/logback-site/src/site/xdocTemplates/shortIntro.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/shortIntro.xml (original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/shortIntro.xml Thu Jan 11 18:56:59 2007
@@ -965,38 +965,48 @@
href="http://logback.qos.ch/translator/">PropertiesTranslator</a>
web-application.
</p>
-
- <p>Let us give a taste of how logback configuration is done with
- the help of a trivial application named <em>MyApp</em>.
+
+ <p>
+ Configuring logback from a XML file is an easy task. One just needs to
+ instanciate a <code>JoranConfigurator</code> and pass the configuration
+ file, as the following example demonstrate.
</p>
- <em>Example 1.3: BasicConfigurator sample usage (<a href="xref/chapter1/MyApp.html">logback-examples/src/main/java/chapter1/MyApp.java</a>)</em>
+ <em>Example 1.4: Logback configuration from file ((<a
+ href="xref/chapter1/MyAppWithConfigFile.html">logback-examples/src/main/java/chapter1/MyAppWithConfigFile.java</a>)</em>
+
<div class="source"><pre>package chapter1;
-// Import SLF4J classes.
-import org.slf4j.LoggerFactory;
+//Import SLF4J classes.
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import ch.qos.logback.classic.BasicConfigurator;
-
-public class MyApp {
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.util.StatusPrinter;
- public static void main(String[] args) {
+public class MyAppWithConfigFile {
- // Set up a simple configuration that logs on the console.
- BasicConfigurator.configureDefaultContext();
+ public static void main(String[] args) {
+ Logger logger = LoggerFactory.getLogger(MyAppWithConfigFile.class);
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure(args[0]);
- Logger logger = LoggerFactory.getLogger(MyApp.class);
-
logger.info("Entering application.");
Bar bar = new Bar();
bar.doIt();
logger.info("Exiting application.");
+
+ StatusPrinter.print(lc.getStatusManager());
}
-}</pre></div>
+}</pre></div>
+
- <p>This class defines a logger instance variable with the name
- <em>MyApp</em>. It then instantiates a <code>Bar</code>
+ <p>This class defines a logger instance variable.
+ It then instantiates a <code>Bar</code>
object. The <code>Bar</code> class is listed below:
</p>
@@ -1015,23 +1025,18 @@
}
}</pre></div>
- <p>The invocation of the <code>configureDefaultContext()</code>
- method in <code>BasicConfigurator</code> creates a minimal logback setup.
- Note that, by default, the root Logger is assigned to <code>Level.DEBUG</code>.
- </p>
-
- <p>
- Running <code>MyApp</code>, by issuing the command <em>java chapter1.MyApp</em>,
- will produce the following output:
+ <p><em>MyAppWithConfigFile</em> configures logback by using the
+ <code>JoranConfigurator</code>. Joran is a XML interpreter, similar to the
+ commons-digester API, but offering several advantages over
+ commons-digester. Here, it parses the xml file and runs actions
+ depending on the tags it finds. To setup the <code>JoranConfigurator</code>
+ properly, we passed the <code>LoggerContext</code>. A
+ <code>LoggerContext</code> is the class that creates and manages
+ Loggers in logback. It is also the class that implements the
+ <code>org.slf4j.ILoggerFactory</code> interface.
</p>
-<div class="source"><pre>22:05:21.461 [main] INFO chapter1.MyApp - Entering application.
-22:05:21.461 [main] DEBUG chapter1.Bar - doing my job
-22:05:21.461 [main] INFO chapter1.MyApp - Exiting application.</pre></div>
-
-<!-- ========= CEKI: STOPPED HERE =================== -->
-
- <p><em>MyApp</em> configures logback by invoking
- <code>BasicConfigurator.configureDefaultContext()</code>. All
+ <p>
+ All
other classes only need to retrieve an instance of
<code>org.slf4j.Logger</code> by calling
<code>LoggerFactory.getLogger()</code>, and then log away. For
@@ -1042,53 +1047,8 @@
logback, but on SLF4J instead.
</p>
- <p>The previous example output logging information always in the
- same fixed format. Fortunately, it is easy to modify an
- application so that logging environment is configured at runtime.
- </p>
-
- <em>Example 1.4: Logback configuration from file ((<a
- href="xref/chapter1/MyAppWithConfigFile.html">logback-examples/src/main/java/chapter1/MyAppWithConfigFile.java</a>)</em>
-
-<div class="source"><pre>package chapter1;
-
-//Import SLF4J classes.
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.joran.JoranConfigurator;
-import ch.qos.logback.core.util.StatusPrinter;
-
-public class MyAppWithConfigFile {
-
- public static void main(String[] args) {
- Logger logger = LoggerFactory.getLogger(MyAppWithConfigFile.class);
- LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
-
- JoranConfigurator configurator = new JoranConfigurator();
- configurator.setContext(lc);
- configurator.doConfigure(args[0]);
-
- logger.info("Entering application.");
- Bar bar = new Bar();
- bar.doIt();
- logger.info("Exiting application.");
-
- StatusPrinter.print(lc.getStatusManager());
- }
-}</pre></div>
-
- <p>MyAppWithConfigFile instructs <code>JoranConfigurator</code>
- to parse a configuration file and to set up logging according to
- the instructions found
- therein.
- </p>
-
- <p>Let us configure logback in the exact same way,
- but this time with an XML configuration file. The next
- configuration file, once executed, will have the same affect as
- calling <code>BasicConfigrator</code>.</p>
+ <p>Let us configure logback with the
+ next XML configuration file:</p>
<em>Example 1.5: Basic configuration with a xml file (logback-examples/src/main/java/chapter1/sample-config-1.xml)</em>
<div class="source"><pre><?xml version="1.0" encoding="UTF-8" ?>
@@ -1122,22 +1082,15 @@
<div class="source"><pre>java chapter1.MyAppWithConfigFile src/main/java/chapter1/sample-config-1.xml</pre></div>
- <p>The console output will be exactly the same as before. However,
- this time, we didn't need to import and call the <code>BasicConfigurator</code>
- class.
- </p>
-
- <p>We used the <code>JoranConfigurator</code> class to parse the configuration
- file we just created. Joran is a XML interpreter, similar to the
- commons-digester API, but offering several advantages over
- commons-digester. Here, it parses the xml file and runs actions
- depending on the tags it finds. To setup the <code>JoranConfigurator</code>
- properly, we passed the <code>LoggerContext</code>. A
- <code>LoggerContext</code> is the class that creates and manages
- Loggers in logback. It is also the class that implements the
- <code>org.slf4j.ILoggerFactory</code> interface.
+ <p>
+ Here is what you should see in the console:
</p>
+<div class="source"><pre>18:15:26.718 [main] INFO chapter1.MyAppWithConfigFile - Entering application.
+18:15:26.718 [main] DEBUG chapter1.Bar - doing my job
+18:15:26.718 [main] INFO chapter1.MyAppWithConfigFile - Exiting application.</pre></div>
+
+
<p>Logging to the console is a rather simple example. Let's now
configure logback so that it logs to the console, but also to a
custom file.</p>
@@ -1225,5 +1178,44 @@
which would log according to local server policy, for example by forwarding the log event
to a second logback server.</p>
+
+ <p>
+ Until now, we always had to specifically load the configuration file and pass it
+ to a logback component. However, this step is not necessary in most cases. When logback
+ is not configured by instanciating <code>JoranConfigurator</code> objects, it follows
+ a simple policy to configure itself.
+ </p>
+
+ <ul>
+ <p>Logback first tries to find a file called <em>logback.xml</em> within the classpath.</p>
+ <p>If no such file is found, it checks for another file called <em>logback-test.xml</em>.</p>
+ <p>In case none of these files are found, logback configures itself automatically using the
+ <a href="../xref/ch/qos/logback/classic/BasicConfigurator.html"><code>BasicConfigurator</code>
+ </a> class.</p>
+ </ul>
+
+ <p>
+ The first two checks allow for two environments to cooperate nicely. When the application
+ using logback is in development and test process, a special file can be used to setup
+ a logging environment that is developer-friendly. Once in production environment, the
+ presence of a <em>logback.xml</em> file overrides any <em>logback-test.xml</em>
+ configuration.
+ </p>
+
+ <p>
+ The last step is meant to provide very basic logging functionnality in case no configuration
+ file is provided. In that case, the logging requests are output to the console.
+ </p>
+
+ <p>
+ Letting logback load its configuration file is the most often used way of
+ configuring. It allows the user to only import SLF4J classes in her code.
+ </p>
+
+ <p>
+ The last step of logback's configuration policy permits the use of a minimal
+ logging configuration right out of the box. Remember the very first example of
+ this short introduction. The output was generated due to this feature.
+ </p>
</body>
</document>
1
0

11 Jan '07
Author: seb
Date: Thu Jan 11 16:17:47 2007
New Revision: 1199
Modified:
logback/trunk/logback-site/src/site/fml/faq.fml
Log:
corrected faq entry
Modified: logback/trunk/logback-site/src/site/fml/faq.fml
==============================================================================
--- logback/trunk/logback-site/src/site/fml/faq.fml (original)
+++ logback/trunk/logback-site/src/site/fml/faq.fml Thu Jan 11 16:17:47 2007
@@ -33,14 +33,12 @@
<em>logback-classic-VERSION.jar</em> .
</p>
-
- <!-- should logback.xml really be placed in JETTY_HOME? -->
-
<p>
To configure logback-classic, a file called
<em>logback.xml</em> should be placed at the root
directory of Jetty, that is the <em>JETTY_HOME</em>
- directory. You can find configuration samples in the
+ directory or in the <em>JETTY_HOME/resources</em> directory,
+ depending on your classpath settings. You can find configuration samples in the
<em>examples/src/chapter4/conf/</em> directory, in the
distribution of logback.
</p>
1
0
Online report : http://localhost:8090/continuum/servlet/continuum/target/ProjectBuild.vm/vi…
Build statistics:
State: Failed
Previous State: Failed
Started at: Thu, 11 Jan 2007 15:40:42 +0100
Finished at: Thu, 11 Jan 2007 15:40:46 +0100
Total time: 4s
Build Trigger: Schedule
Exit code: 1
Building machine hostname: pixie
Operating system : Linux(unknown)
Java version : 1.5.0_08(Sun Microsystems Inc.)
Changes
src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java
src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java
src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java
****************************************************************************
Output:
****************************************************************************
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Logback Classic Module
[INFO] task-segment: [clean, install]
[INFO] ----------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /opt/continuum-1.0.3/apps/continuum/working-directory/46/target
[INFO] Deleting directory /opt/continuum-1.0.3/apps/continuum/working-directory/46/target/classes
[INFO] Deleting directory /opt/continuum-1.0.3/apps/continuum/working-directory/46/target/test-classes
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
Downloading: http://repo1.maven.org/maven2/javax/jms/jms/1.1/jms-1.1.jar
[WARNING] Unable to get resource from repository central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) javax.jms:jms:jar:1.1
Try downloading the file manually from:
http://java.sun.com/products/jms/docs.html
Then, install it using the command:
mvn install:install-file -DgroupId=javax.jms -DartifactId=jms \
-Dversion=1.1 -Dpackaging=jar -Dfile=/path/to/file
Path to dependency:
1) ch.qos.logback:logback-classic:jar:0.8-SNAPSHOT
2) javax.jms:jms:jar:1.1
----------
1 required artifact is missing.
for artifact:
ch.qos.logback:logback-classic:jar:0.8-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Thu Jan 11 15:40:46 CET 2007
[INFO] Final Memory: 11M/82M
[INFO] ------------------------------------------------------------------------
****************************************************************************
1
0

svn commit: r1198 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic/net logback-classic/src/test/java/ch/qos/logback/classic/net logback-core/src/main/java/ch/qos/logback/core/net
by noreply.seb@qos.ch 11 Jan '07
by noreply.seb@qos.ch 11 Jan '07
11 Jan '07
Author: seb
Date: Thu Jan 11 15:22:14 2007
New Revision: 1198
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java
Removed:
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTestApp.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTestApp.java
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
Log:
Refactored JMS**Appender.
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java Thu Jan 11 15:22:14 2007
@@ -10,9 +10,6 @@
package ch.qos.logback.classic.net;
-import java.util.Hashtable;
-import java.util.Properties;
-
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
@@ -22,11 +19,9 @@
import javax.jms.Session;
import javax.naming.Context;
import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
import ch.qos.logback.classic.spi.LoggingEvent;
-import ch.qos.logback.core.AppenderBase;
+import ch.qos.logback.core.net.JMSAppenderBase;
/**
* A simple appender that publishes events to a JMS Queue. The events are
@@ -98,19 +93,12 @@
*
* @author Ceki Gülcü
*/
-public class JMSQueueAppender extends AppenderBase<LoggingEvent> {
+public class JMSQueueAppender extends JMSAppenderBase<LoggingEvent> {
static int SUCCESSIVE_FAILURE_LIMIT = 3;
- String securityPrincipalName;
- String securityCredentials;
- String initialContextFactoryName;
- String urlPkgPrefixes;
- String providerURL;
String queueBindingName;
String qcfBindingName;
- String userName;
- String password;
QueueConnection queueConnection;
QueueSession queueSession;
QueueSender queueSender;
@@ -198,53 +186,6 @@
}
}
- public Context buildJNDIContext() throws NamingException {
- Context jndi = null;
-
- // addInfo("Getting initial context.");
- if (initialContextFactoryName != null) {
- Properties env = buildEnvProperties();
- jndi = new InitialContext(env);
- } else {
- jndi = new InitialContext();
- }
- return jndi;
- }
-
- public Properties buildEnvProperties() {
- Properties env = new Properties();
- env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
- if (providerURL != null) {
- env.put(Context.PROVIDER_URL, providerURL);
- } else {
- addWarn("You have set InitialContextFactoryName option but not the "
- + "ProviderURL. This is likely to cause problems.");
- }
- if (urlPkgPrefixes != null) {
- env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
- }
-
- if (securityPrincipalName != null) {
- env.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
- if (securityCredentials != null) {
- env.put(Context.SECURITY_CREDENTIALS, securityCredentials);
- } else {
- addWarn("You have set SecurityPrincipalName option but not the "
- + "SecurityCredentials. This is likely to cause problems.");
- }
- }
- return env;
- }
-
- protected Object lookup(Context ctx, String name) throws NamingException {
- try {
- return ctx.lookup(name);
- } catch (NameNotFoundException e) {
- addError("Could not find name [" + name + "].");
- throw e;
- }
- }
-
/**
* Close this JMSAppender. Closing releases all resources used by the
* appender. A closed appender cannot be re-opened.
@@ -293,92 +234,12 @@
if (successiveFailureCount > SUCCESSIVE_FAILURE_LIMIT) {
stop();
}
- addError("Could not send message in JMSAppender [" + name + "].", e);
+ addError("Could not send message in JMSQueueAppender [" + name + "].", e);
}
}
/**
- * Returns the value of the <b>InitialContextFactoryName</b> option. See
- * {@link #setInitialContextFactoryName} for more details on the meaning of
- * this option.
- */
- public String getInitialContextFactoryName() {
- return initialContextFactoryName;
- }
-
- /**
- * Setting the <b>InitialContextFactoryName</b> method will cause this
- * <code>JMSAppender</code> instance to use the {@link
- * InitialContext#InitialContext(Hashtable)} method instead of the no-argument
- * constructor. If you set this option, you should also at least set the
- * <b>ProviderURL</b> option.
- *
- * <p>
- * See also {@link #setProviderURL(String)}.
- */
- public void setInitialContextFactoryName(String initialContextFactoryName) {
- this.initialContextFactoryName = initialContextFactoryName;
- }
-
- public String getProviderURL() {
- return providerURL;
- }
-
- public void setProviderURL(String providerURL) {
- this.providerURL = providerURL;
- }
-
- String getURLPkgPrefixes() {
- return urlPkgPrefixes;
- }
-
- public void setURLPkgPrefixes(String urlPkgPrefixes) {
- this.urlPkgPrefixes = urlPkgPrefixes;
- }
-
- public String getSecurityCredentials() {
- return securityCredentials;
- }
-
- public void setSecurityCredentials(String securityCredentials) {
- this.securityCredentials = securityCredentials;
- }
-
- public String getSecurityPrincipalName() {
- return securityPrincipalName;
- }
-
- public void setSecurityPrincipalName(String securityPrincipalName) {
- this.securityPrincipalName = securityPrincipalName;
- }
-
- public String getUserName() {
- return userName;
- }
-
- /**
- * The user name to use when {@link
- * javax.jms.TopicConnectionFactory#createTopicConnection(String, String)}
- * creating a topic session}. If you set this option, you should also set the
- * <b>Password</b> option. See {@link #setPassword(String)}.
- */
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- public String getPassword() {
- return password;
- }
-
- /**
- * The paswword to use when creating a topic session.
- */
- public void setPassword(String password) {
- this.password = password;
- }
-
- /**
* Returns the QueueConnection used for this appender. Only valid after
* start() method has been invoked.
*/
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSTopicAppender.java Thu Jan 11 15:22:14 2007
@@ -10,9 +10,6 @@
package ch.qos.logback.classic.net;
-import java.util.Hashtable;
-import java.util.Properties;
-
import javax.jms.ObjectMessage;
import javax.jms.Session;
import javax.jms.Topic;
@@ -22,11 +19,9 @@
import javax.jms.TopicSession;
import javax.naming.Context;
import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
import ch.qos.logback.classic.spi.LoggingEvent;
-import ch.qos.logback.core.AppenderBase;
+import ch.qos.logback.core.net.JMSAppenderBase;
/**
* A simple appender that publishes events to a JMS Topic. The events are
@@ -98,19 +93,12 @@
*
* @author Ceki Gülcü
*/
-public class JMSTopicAppender extends AppenderBase<LoggingEvent> {
+public class JMSTopicAppender extends JMSAppenderBase<LoggingEvent> {
static int SUCCESSIVE_FAILURE_LIMIT = 3;
- String securityPrincipalName;
- String securityCredentials;
- String initialContextFactoryName;
- String urlPkgPrefixes;
- String providerURL;
String topicBindingName;
String tcfBindingName;
- String userName;
- String password;
TopicConnection topicConnection;
TopicSession topicSession;
TopicPublisher topicPublisher;
@@ -198,53 +186,6 @@
}
}
- public Context buildJNDIContext() throws NamingException {
- Context jndi = null;
-
- // addInfo("Getting initial context.");
- if (initialContextFactoryName != null) {
- Properties env = buildEnvProperties();
- jndi = new InitialContext(env);
- } else {
- jndi = new InitialContext();
- }
- return jndi;
- }
-
- public Properties buildEnvProperties() {
- Properties env = new Properties();
- env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
- if (providerURL != null) {
- env.put(Context.PROVIDER_URL, providerURL);
- } else {
- addWarn("You have set InitialContextFactoryName option but not the "
- + "ProviderURL. This is likely to cause problems.");
- }
- if (urlPkgPrefixes != null) {
- env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
- }
-
- if (securityPrincipalName != null) {
- env.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
- if (securityCredentials != null) {
- env.put(Context.SECURITY_CREDENTIALS, securityCredentials);
- } else {
- addWarn("You have set SecurityPrincipalName option but not the "
- + "SecurityCredentials. This is likely to cause problems.");
- }
- }
- return env;
- }
-
- protected Object lookup(Context ctx, String name) throws NamingException {
- try {
- return ctx.lookup(name);
- } catch (NameNotFoundException e) {
- addError("Could not find name [" + name + "].");
- throw e;
- }
- }
-
/**
* Close this JMSAppender. Closing releases all resources used by the
* appender. A closed appender cannot be re-opened.
@@ -300,86 +241,6 @@
}
/**
- * Returns the value of the <b>InitialContextFactoryName</b> option. See
- * {@link #setInitialContextFactoryName} for more details on the meaning of
- * this option.
- */
- public String getInitialContextFactoryName() {
- return initialContextFactoryName;
- }
-
- /**
- * Setting the <b>InitialContextFactoryName</b> method will cause this
- * <code>JMSAppender</code> instance to use the {@link
- * InitialContext#InitialContext(Hashtable)} method instead of the no-argument
- * constructor. If you set this option, you should also at least set the
- * <b>ProviderURL</b> option.
- *
- * <p>
- * See also {@link #setProviderURL(String)}.
- */
- public void setInitialContextFactoryName(String initialContextFactoryName) {
- this.initialContextFactoryName = initialContextFactoryName;
- }
-
- public String getProviderURL() {
- return providerURL;
- }
-
- public void setProviderURL(String providerURL) {
- this.providerURL = providerURL;
- }
-
- String getURLPkgPrefixes() {
- return urlPkgPrefixes;
- }
-
- public void setURLPkgPrefixes(String urlPkgPrefixes) {
- this.urlPkgPrefixes = urlPkgPrefixes;
- }
-
- public String getSecurityCredentials() {
- return securityCredentials;
- }
-
- public void setSecurityCredentials(String securityCredentials) {
- this.securityCredentials = securityCredentials;
- }
-
- public String getSecurityPrincipalName() {
- return securityPrincipalName;
- }
-
- public void setSecurityPrincipalName(String securityPrincipalName) {
- this.securityPrincipalName = securityPrincipalName;
- }
-
- public String getUserName() {
- return userName;
- }
-
- /**
- * The user name to use when {@link
- * javax.jms.TopicConnectionFactory#createTopicConnection(String, String)}
- * creating a topic session}. If you set this option, you should also set the
- * <b>Password</b> option. See {@link #setPassword(String)}.
- */
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- public String getPassword() {
- return password;
- }
-
- /**
- * The paswword to use when creating a topic session.
- */
- public void setPassword(String password) {
- this.password = password;
- }
-
- /**
* Returns the TopicConnection used for this appender. Only valid after
* start() method has been invoked.
*/
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java Thu Jan 11 15:22:14 2007
@@ -1,9 +1,6 @@
package ch.qos.logback.classic.net;
-import java.util.Properties;
-
import javax.jms.ObjectMessage;
-import javax.naming.Context;
import junit.framework.TestCase;
import ch.qos.logback.classic.Level;
@@ -28,8 +25,8 @@
appender.setName("jmsQueue");
appender.qcfBindingName = "queueCnxFactory";
appender.queueBindingName = "testQueue";
- appender.providerURL = "url";
- appender.initialContextFactoryName = MockInitialContextFactory.class.getName();
+ appender.setProviderURL("url");
+ appender.setInitialContextFactoryName(MockInitialContextFactory.class.getName());
MockInitialContext mic = MockInitialContextFactory.getContext();
mic.map.put(appender.qcfBindingName, new MockQueueConnectionFactory());
@@ -78,96 +75,10 @@
assertFalse(appender.isStarted());
}
- public void testBuildEnvProperties() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = "url";
- appender.urlPkgPrefixes = "pkgPref";
- appender.securityPrincipalName = "user";
- appender.securityCredentials = "cred";
-
- Properties props = appender.buildEnvProperties();
- assertEquals(5, props.size());
- assertEquals(appender.initialContextFactoryName, props
- .getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
- assertEquals(appender.urlPkgPrefixes, props
- .getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
- .getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(appender.securityCredentials, props
- .getProperty(Context.SECURITY_CREDENTIALS));
- }
-
- public void testBuildEnvPropertiesWithNullProviderURL() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = null;
- appender.urlPkgPrefixes = "pkgPref";
- appender.securityPrincipalName = "user";
- appender.securityCredentials = "cred";
-
- Properties props = appender.buildEnvProperties();
- assertEquals(4, props.size());
- assertEquals(appender.initialContextFactoryName, props
- .getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(null, props.getProperty(Context.PROVIDER_URL));
- assertEquals(appender.urlPkgPrefixes, props
- .getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
- .getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(appender.securityCredentials, props
- .getProperty(Context.SECURITY_CREDENTIALS));
-
- assertEquals(1, context.getStatusManager().getCount());
- }
-
- public void testBuildEnvPropertiesWithNullCredentials() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = "url";
- appender.urlPkgPrefixes = "pkgPref";
- appender.securityPrincipalName = "user";
- appender.securityCredentials = null;
-
- Properties props = appender.buildEnvProperties();
- assertEquals(4, props.size());
- assertEquals(appender.initialContextFactoryName, props
- .getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
- assertEquals(appender.urlPkgPrefixes, props
- .getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
- .getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(null, props
- .getProperty(Context.SECURITY_CREDENTIALS));
-
- assertEquals(1, context.getStatusManager().getCount());
- }
-
- public void testBuildEnvPropertiesWithPkgNull() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = "url";
- appender.urlPkgPrefixes = null;
- appender.securityPrincipalName = "user";
- appender.securityCredentials = "cred";
-
- Properties props = appender.buildEnvProperties();
- assertEquals(4, props.size());
- assertEquals(appender.initialContextFactoryName, props
- .getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
- assertEquals(null, props
- .getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
- .getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(appender.securityCredentials, props
- .getProperty(Context.SECURITY_CREDENTIALS));
-
- assertEquals(0, context.getStatusManager().getCount());
- }
-
public void testStartMinimalInfo() {
//let's leave only what's in the setup()
//method, minus the providerURL
- appender.providerURL = null;
+ appender.setProviderURL(null);
appender.start();
assertTrue(appender.isStarted());
@@ -180,8 +91,8 @@
}
public void testStartUserPass() {
- appender.userName = "";
- appender.password = "";
+ appender.setUserName("test");
+ appender.setPassword("test");
appender.start();
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java Thu Jan 11 15:22:14 2007
@@ -28,8 +28,8 @@
appender.setName("jmsTopic");
appender.tcfBindingName = "topicCnxFactory";
appender.topicBindingName = "testTopic";
- appender.providerURL = "url";
- appender.initialContextFactoryName = MockInitialContextFactory.class.getName();
+ appender.setProviderURL("url");
+ appender.setInitialContextFactoryName(MockInitialContextFactory.class.getName());
MockInitialContext mic = MockInitialContextFactory.getContext();
mic.map.put(appender.tcfBindingName, new MockTopicConnectionFactory());
@@ -79,62 +79,62 @@
}
public void testBuildEnvProperties() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = "url";
- appender.urlPkgPrefixes = "pkgPref";
- appender.securityPrincipalName = "user";
- appender.securityCredentials = "cred";
+ appender.setInitialContextFactoryName("icfn");
+ appender.setProviderURL("url");
+ appender.setURLPkgPrefixes("pkgPref");
+ appender.setSecurityPrincipalName("user");
+ appender.setSecurityCredentials("cred");
Properties props = appender.buildEnvProperties();
assertEquals(5, props.size());
- assertEquals(appender.initialContextFactoryName, props
+ assertEquals(appender.getInitialContextFactoryName(), props
.getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
- assertEquals(appender.urlPkgPrefixes, props
+ assertEquals(appender.getProviderURL(), props.getProperty(Context.PROVIDER_URL));
+ assertEquals(appender.getURLPkgPrefixes(), props
.getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
+ assertEquals(appender.getSecurityPrincipalName(), props
.getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(appender.securityCredentials, props
+ assertEquals(appender.getSecurityCredentials(), props
.getProperty(Context.SECURITY_CREDENTIALS));
}
public void testBuildEnvPropertiesWithNullProviderURL() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = null;
- appender.urlPkgPrefixes = "pkgPref";
- appender.securityPrincipalName = "user";
- appender.securityCredentials = "cred";
+ appender.setInitialContextFactoryName("icfn");
+ appender.setProviderURL(null);
+ appender.setURLPkgPrefixes("pkgPref");
+ appender.setSecurityPrincipalName("user");
+ appender.setSecurityCredentials("cred");
Properties props = appender.buildEnvProperties();
assertEquals(4, props.size());
- assertEquals(appender.initialContextFactoryName, props
+ assertEquals(appender.getInitialContextFactoryName(), props
.getProperty(Context.INITIAL_CONTEXT_FACTORY));
assertEquals(null, props.getProperty(Context.PROVIDER_URL));
- assertEquals(appender.urlPkgPrefixes, props
+ assertEquals(appender.getURLPkgPrefixes(), props
.getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
+ assertEquals(appender.getSecurityPrincipalName(), props
.getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(appender.securityCredentials, props
+ assertEquals(appender.getSecurityCredentials(), props
.getProperty(Context.SECURITY_CREDENTIALS));
assertEquals(1, context.getStatusManager().getCount());
}
public void testBuildEnvPropertiesWithNullCredentials() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = "url";
- appender.urlPkgPrefixes = "pkgPref";
- appender.securityPrincipalName = "user";
- appender.securityCredentials = null;
+ appender.setInitialContextFactoryName("icfn");
+ appender.setProviderURL("url");
+ appender.setURLPkgPrefixes("pkgPref");
+ appender.setSecurityPrincipalName("user");
+ appender.setSecurityCredentials(null);
Properties props = appender.buildEnvProperties();
assertEquals(4, props.size());
- assertEquals(appender.initialContextFactoryName, props
+ assertEquals(appender.getInitialContextFactoryName(), props
.getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
- assertEquals(appender.urlPkgPrefixes, props
+ assertEquals(appender.getProviderURL(), props.getProperty(Context.PROVIDER_URL));
+ assertEquals(appender.getURLPkgPrefixes(), props
.getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
+ assertEquals(appender.getSecurityPrincipalName(), props
.getProperty(Context.SECURITY_PRINCIPAL));
assertEquals(null, props
.getProperty(Context.SECURITY_CREDENTIALS));
@@ -143,22 +143,22 @@
}
public void testBuildEnvPropertiesWithPkgNull() {
- appender.initialContextFactoryName = "icfn";
- appender.providerURL = "url";
- appender.urlPkgPrefixes = null;
- appender.securityPrincipalName = "user";
- appender.securityCredentials = "cred";
+ appender.setInitialContextFactoryName("icfn");
+ appender.setProviderURL("url");
+ appender.setURLPkgPrefixes(null);
+ appender.setSecurityPrincipalName("user");
+ appender.setSecurityCredentials("cred");
Properties props = appender.buildEnvProperties();
assertEquals(4, props.size());
- assertEquals(appender.initialContextFactoryName, props
+ assertEquals(appender.getInitialContextFactoryName(), props
.getProperty(Context.INITIAL_CONTEXT_FACTORY));
- assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
+ assertEquals(appender.getProviderURL(), props.getProperty(Context.PROVIDER_URL));
assertEquals(null, props
.getProperty(Context.URL_PKG_PREFIXES));
- assertEquals(appender.securityPrincipalName, props
+ assertEquals(appender.getSecurityPrincipalName(), props
.getProperty(Context.SECURITY_PRINCIPAL));
- assertEquals(appender.securityCredentials, props
+ assertEquals(appender.getSecurityCredentials(), props
.getProperty(Context.SECURITY_CREDENTIALS));
assertEquals(0, context.getStatusManager().getCount());
@@ -167,7 +167,7 @@
public void testStartMinimalInfo() {
//let's leave only what's in the setup()
//method, minus the providerURL
- appender.providerURL = null;
+ appender.setProviderURL(null);
appender.start();
assertTrue(appender.isStarted());
@@ -180,8 +180,8 @@
}
public void testStartUserPass() {
- appender.userName = "";
- appender.password = "";
+ appender.setUserName("test");
+ appender.setPassword("test");
appender.start();
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/JMSAppenderBase.java Thu Jan 11 15:22:14 2007
@@ -0,0 +1,163 @@
+package ch.qos.logback.core.net;
+
+import java.util.Hashtable;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import ch.qos.logback.core.AppenderBase;
+
+/**
+ * This class serves as a base class for
+ * JMSTopicAppender and JMSQueueAppender
+ *
+ * @author Ceki Gülcü
+ * @author Sébastien Pennec
+ */
+public abstract class JMSAppenderBase<E> extends AppenderBase<E> {
+
+ protected String securityPrincipalName;
+ protected String securityCredentials;
+ protected String initialContextFactoryName;
+ protected String urlPkgPrefixes;
+ protected String providerURL;
+ protected String userName;
+ protected String password;
+
+
+ protected Object lookup(Context ctx, String name) throws NamingException {
+ try {
+ return ctx.lookup(name);
+ } catch (NameNotFoundException e) {
+ addError("Could not find name [" + name + "].");
+ throw e;
+ }
+ }
+
+ public Context buildJNDIContext() throws NamingException {
+ Context jndi = null;
+
+ // addInfo("Getting initial context.");
+ if (initialContextFactoryName != null) {
+ Properties env = buildEnvProperties();
+ jndi = new InitialContext(env);
+ } else {
+ jndi = new InitialContext();
+ }
+ return jndi;
+ }
+
+ public Properties buildEnvProperties() {
+ Properties env = new Properties();
+ env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
+ if (providerURL != null) {
+ env.put(Context.PROVIDER_URL, providerURL);
+ } else {
+ addWarn("You have set InitialContextFactoryName option but not the "
+ + "ProviderURL. This is likely to cause problems.");
+ }
+ if (urlPkgPrefixes != null) {
+ env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
+ }
+
+ if (securityPrincipalName != null) {
+ env.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
+ if (securityCredentials != null) {
+ env.put(Context.SECURITY_CREDENTIALS, securityCredentials);
+ } else {
+ addWarn("You have set SecurityPrincipalName option but not the "
+ + "SecurityCredentials. This is likely to cause problems.");
+ }
+ }
+ return env;
+ }
+
+
+
+ /**
+ * Returns the value of the <b>InitialContextFactoryName</b> option. See
+ * {@link #setInitialContextFactoryName} for more details on the meaning of
+ * this option.
+ */
+ public String getInitialContextFactoryName() {
+ return initialContextFactoryName;
+ }
+
+ /**
+ * Setting the <b>InitialContextFactoryName</b> method will cause this
+ * <code>JMSAppender</code> instance to use the {@link
+ * InitialContext#InitialContext(Hashtable)} method instead of the no-argument
+ * constructor. If you set this option, you should also at least set the
+ * <b>ProviderURL</b> option.
+ *
+ * <p>
+ * See also {@link #setProviderURL(String)}.
+ */
+ public void setInitialContextFactoryName(String initialContextFactoryName) {
+ this.initialContextFactoryName = initialContextFactoryName;
+ }
+
+ public String getProviderURL() {
+ return providerURL;
+ }
+
+ public void setProviderURL(String providerURL) {
+ this.providerURL = providerURL;
+ }
+
+ public String getURLPkgPrefixes() {
+ return urlPkgPrefixes;
+ }
+
+ public void setURLPkgPrefixes(String urlPkgPrefixes) {
+ this.urlPkgPrefixes = urlPkgPrefixes;
+ }
+
+ public String getSecurityCredentials() {
+ return securityCredentials;
+ }
+
+ public void setSecurityCredentials(String securityCredentials) {
+ this.securityCredentials = securityCredentials;
+ }
+
+ public String getSecurityPrincipalName() {
+ return securityPrincipalName;
+ }
+
+ public void setSecurityPrincipalName(String securityPrincipalName) {
+ this.securityPrincipalName = securityPrincipalName;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ /**
+ * The user name to use when {@link
+ * javax.jms.TopicConnectionFactory#createTopicConnection(String, String)}
+ * creating a topic session}. If you set this option, you should also set the
+ * <b>Password</b> option. See {@link #setPassword(String)}.
+ */
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * The paswword to use when creating a topic session.
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+
+
+
+}
1
0
Online report : http://localhost:8090/continuum/servlet/continuum/target/ProjectBuild.vm/vi…
Build statistics:
State: Failed
Previous State: Failed
Started at: Thu, 11 Jan 2007 14:40:20 +0100
Finished at: Thu, 11 Jan 2007 14:40:24 +0100
Total time: 4s
Build Trigger: Schedule
Exit code: 1
Building machine hostname: pixie
Operating system : Linux(unknown)
Java version : 1.5.0_08(Sun Microsystems Inc.)
Changes
src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
src/test/java/ch/qos/logback/classic/net/mock/MockQueueSender.java
src/test/java/ch/qos/logback/classic/net/mock/MockQueueSession.java
src/test/java/ch/qos/logback/classic/net/mock/MockQueueConnectionFactory.java
src/test/java/ch/qos/logback/classic/net/mock/MockQueue.java
src/test/java/ch/qos/logback/classic/net/mock/MockQueueConnection.java
src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java
src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java
****************************************************************************
Output:
****************************************************************************
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Logback Classic Module
[INFO] task-segment: [clean, install]
[INFO] ----------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /opt/continuum-1.0.3/apps/continuum/working-directory/46/target
[INFO] Deleting directory /opt/continuum-1.0.3/apps/continuum/working-directory/46/target/classes
[INFO] Deleting directory /opt/continuum-1.0.3/apps/continuum/working-directory/46/target/test-classes
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
Downloading: http://repo1.maven.org/maven2/javax/jms/jms/1.1/jms-1.1.jar
[WARNING] Unable to get resource from repository central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) javax.jms:jms:jar:1.1
Try downloading the file manually from:
http://java.sun.com/products/jms/docs.html
Then, install it using the command:
mvn install:install-file -DgroupId=javax.jms -DartifactId=jms \
-Dversion=1.1 -Dpackaging=jar -Dfile=/path/to/file
Path to dependency:
1) ch.qos.logback:logback-classic:jar:0.8-SNAPSHOT
2) javax.jms:jms:jar:1.1
----------
1 required artifact is missing.
for artifact:
ch.qos.logback:logback-classic:jar:0.8-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Thu Jan 11 14:40:24 CET 2007
[INFO] Final Memory: 11M/83M
[INFO] ------------------------------------------------------------------------
****************************************************************************
1
0

svn commit: r1197 - in logback/trunk/logback-classic/src: main/java/ch/qos/logback/classic/net test/java/ch/qos/logback/classic/net test/java/ch/qos/logback/classic/net/mock
by noreply.seb@qos.ch 11 Jan '07
by noreply.seb@qos.ch 11 Jan '07
11 Jan '07
Author: seb
Date: Thu Jan 11 14:36:49 2007
New Revision: 1197
Added:
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueue.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueueConnection.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueueConnectionFactory.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueueSender.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueueSession.java
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
Log:
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/JMSQueueAppender.java Thu Jan 11 14:36:49 2007
@@ -40,10 +40,10 @@
* requires the retreival of a JNDI {@link Context}.
*
* <p>
- * There are two common methods for retrieving a JNDI {@link Context}. If a file
- * resource named <em>jndi.properties</em> is available to the JNDI API, it
- * will use the information found therein to retrieve an initial JNDI context.
- * To obtain an initial context, your code will simply call:
+ * There are two common methods for retrieving a JNDI {@link Context}. If a
+ * file resource named <em>jndi.properties</em> is available to the JNDI API,
+ * it will use the information found therein to retrieve an initial JNDI
+ * context. To obtain an initial context, your code will simply call:
*
* <pre>
* InitialContext jndiContext = new InitialContext();
@@ -115,7 +115,6 @@
QueueSession queueSession;
QueueSender queueSender;
- boolean inOrder = false;
int successiveFailureCount = 0;
public JMSQueueAppender() {
@@ -159,79 +158,82 @@
QueueConnectionFactory queueConnectionFactory;
try {
- Context jndi;
+ Context jndi = buildJNDIContext();
- //addInfo("Getting initial context.");
- if (initialContextFactoryName != null) {
- Properties env = new Properties();
- env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
- if (providerURL != null) {
- env.put(Context.PROVIDER_URL, providerURL);
- } else {
- addWarn(
- "You have set InitialContextFactoryName option but not the "
- + "ProviderURL. This is likely to cause problems.");
- }
- if (urlPkgPrefixes != null) {
- env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
- }
-
- if (securityPrincipalName != null) {
- env.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
- if (securityCredentials != null) {
- env.put(Context.SECURITY_CREDENTIALS, securityCredentials);
- } else {
- addWarn(
- "You have set SecurityPrincipalName option but not the "
- + "SecurityCredentials. This is likely to cause problems.");
- }
- }
- jndi = new InitialContext(env);
- } else {
- jndi = new InitialContext();
- }
-
- //addInfo("Looking up [" + qcfBindingName + "]");
- queueConnectionFactory =
- (QueueConnectionFactory) lookup(jndi, qcfBindingName);
- //addInfo("About to create QueueConnection.");
+ // addInfo("Looking up [" + qcfBindingName + "]");
+ queueConnectionFactory = (QueueConnectionFactory) lookup(jndi,
+ qcfBindingName);
+ // addInfo("About to create QueueConnection.");
if (userName != null) {
- this.queueConnection =
- queueConnectionFactory.createQueueConnection(userName, password);
+ this.queueConnection = queueConnectionFactory.createQueueConnection(
+ userName, password);
} else {
this.queueConnection = queueConnectionFactory.createQueueConnection();
}
- //addInfo(
- // "Creating QueueSession, non-transactional, "
- // + "in AUTO_ACKNOWLEDGE mode.");
- this.queueSession =
- queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ // addInfo(
+ // "Creating QueueSession, non-transactional, "
+ // + "in AUTO_ACKNOWLEDGE mode.");
+ this.queueSession = queueConnection.createQueueSession(false,
+ Session.AUTO_ACKNOWLEDGE);
- //addInfo("Looking up queue name [" + queueBindingName + "].");
+ // addInfo("Looking up queue name [" + queueBindingName + "].");
Queue queue = (Queue) lookup(jndi, queueBindingName);
- //addInfo("Creating QueueSender.");
+ // addInfo("Creating QueueSender.");
this.queueSender = queueSession.createSender(queue);
- //addInfo("Starting QueueConnection.");
+ // addInfo("Starting QueueConnection.");
queueConnection.start();
jndi.close();
} catch (Exception e) {
- addError(
- "Error while activating options for appender named [" + name + "].", e);
+ addError("Error while activating options for appender named [" + name
+ + "].", e);
}
-
-
- if (this.queueConnection != null && this.queueSession != null && this.queueSender != null) {
- inOrder = true;
+
+ if (this.queueConnection != null && this.queueSession != null
+ && this.queueSender != null) {
+ super.start();
+ }
+ }
+
+ public Context buildJNDIContext() throws NamingException {
+ Context jndi = null;
+
+ // addInfo("Getting initial context.");
+ if (initialContextFactoryName != null) {
+ Properties env = buildEnvProperties();
+ jndi = new InitialContext(env);
+ } else {
+ jndi = new InitialContext();
+ }
+ return jndi;
+ }
+
+ public Properties buildEnvProperties() {
+ Properties env = new Properties();
+ env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName);
+ if (providerURL != null) {
+ env.put(Context.PROVIDER_URL, providerURL);
} else {
- inOrder = false;
+ addWarn("You have set InitialContextFactoryName option but not the "
+ + "ProviderURL. This is likely to cause problems.");
}
- if(inOrder) {
- super.start();
+ if (urlPkgPrefixes != null) {
+ env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes);
}
+
+ if (securityPrincipalName != null) {
+ env.put(Context.SECURITY_PRINCIPAL, securityPrincipalName);
+ if (securityCredentials != null) {
+ env.put(Context.SECURITY_CREDENTIALS, securityCredentials);
+ } else {
+ addWarn("You have set SecurityPrincipalName option but not the "
+ + "SecurityCredentials. This is likely to cause problems.");
+ }
+ }
+ return env;
}
protected Object lookup(Context ctx, String name) throws NamingException {
@@ -273,35 +275,23 @@
}
/**
- * Gets whether appender is properly configured to append messages.
- *
- * @return true if properly configured.
- */
- protected boolean checkEntryConditions() {
- return inOrder;
- }
-
- /**
* This method called by {@link AppenderSkeleton#doAppend} method to do most
* of the real appending work.
*/
public void append(LoggingEvent event) {
- if (!checkEntryConditions()) {
+ if (!isStarted()) {
return;
}
try {
ObjectMessage msg = queueSession.createObjectMessage();
-
- // manage caller data
-
msg.setObject(event);
queueSender.send(msg);
successiveFailureCount = 0;
} catch (Exception e) {
successiveFailureCount++;
if (successiveFailureCount > SUCCESSIVE_FAILURE_LIMIT) {
- inOrder = false;
+ stop();
}
addError("Could not send message in JMSAppender [" + name + "].", e);
@@ -397,16 +387,16 @@
}
/**
- * Returns the QueueSession used for this appender. Only valid after
- * start() method has been invoked.
+ * Returns the QueueSession used for this appender. Only valid after start()
+ * method has been invoked.
*/
protected QueueSession getQueueSession() {
return queueSession;
}
/**
- * Returns the QueueSender used for this appender. Only valid after
- * start() method has been invoked.
+ * Returns the QueueSender used for this appender. Only valid after start()
+ * method has been invoked.
*/
protected QueueSender getQueueSender() {
return queueSender;
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java Thu Jan 11 14:36:49 2007
@@ -0,0 +1,213 @@
+package ch.qos.logback.classic.net;
+
+import java.util.Properties;
+
+import javax.jms.ObjectMessage;
+import javax.naming.Context;
+
+import junit.framework.TestCase;
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.net.mock.MockInitialContext;
+import ch.qos.logback.classic.net.mock.MockInitialContextFactory;
+import ch.qos.logback.classic.net.mock.MockQueue;
+import ch.qos.logback.classic.net.mock.MockQueueConnectionFactory;
+import ch.qos.logback.classic.net.mock.MockQueueSender;
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.ContextBase;
+
+public class JMSQueueAppenderTest extends TestCase {
+
+ ch.qos.logback.core.Context context;
+ JMSQueueAppender appender;
+
+ @Override
+ protected void setUp() throws Exception {
+ context = new ContextBase();
+ appender = new JMSQueueAppender();
+ appender.setContext(context);
+ appender.setName("jmsQueue");
+ appender.qcfBindingName = "queueCnxFactory";
+ appender.queueBindingName = "testQueue";
+ appender.providerURL = "url";
+ appender.initialContextFactoryName = MockInitialContextFactory.class.getName();
+
+ MockInitialContext mic = MockInitialContextFactory.getContext();
+ mic.map.put(appender.qcfBindingName, new MockQueueConnectionFactory());
+ mic.map.put(appender.queueBindingName, new MockQueue(appender.queueBindingName));
+
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ appender = null;
+ context = null;
+ super.tearDown();
+ }
+
+ public void testAppendOk() {
+ appender.start();
+
+ LoggingEvent le = createLoggingEvent();
+ appender.append(le);
+
+ MockQueueSender qs = (MockQueueSender)appender.queueSender;
+ assertEquals(1, qs.getMessageList().size());
+ ObjectMessage message = (ObjectMessage) qs.getMessageList().get(0);
+ try {
+ assertEquals(le, message.getObject());
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ public void testAppendFailure() {
+ appender.start();
+
+ //make sure the append method does not work
+ appender.queueSender = null;
+
+ LoggingEvent le = createLoggingEvent();
+ for (int i = 1; i <= 3; i++) {
+ appender.append(le);
+ assertEquals(i, context.getStatusManager().getCount());
+ assertTrue(appender.isStarted());
+ }
+ appender.append(le);
+ assertEquals(4, context.getStatusManager().getCount());
+ assertFalse(appender.isStarted());
+ }
+
+ public void testBuildEnvProperties() {
+ appender.initialContextFactoryName = "icfn";
+ appender.providerURL = "url";
+ appender.urlPkgPrefixes = "pkgPref";
+ appender.securityPrincipalName = "user";
+ appender.securityCredentials = "cred";
+
+ Properties props = appender.buildEnvProperties();
+ assertEquals(5, props.size());
+ assertEquals(appender.initialContextFactoryName, props
+ .getProperty(Context.INITIAL_CONTEXT_FACTORY));
+ assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
+ assertEquals(appender.urlPkgPrefixes, props
+ .getProperty(Context.URL_PKG_PREFIXES));
+ assertEquals(appender.securityPrincipalName, props
+ .getProperty(Context.SECURITY_PRINCIPAL));
+ assertEquals(appender.securityCredentials, props
+ .getProperty(Context.SECURITY_CREDENTIALS));
+ }
+
+ public void testBuildEnvPropertiesWithNullProviderURL() {
+ appender.initialContextFactoryName = "icfn";
+ appender.providerURL = null;
+ appender.urlPkgPrefixes = "pkgPref";
+ appender.securityPrincipalName = "user";
+ appender.securityCredentials = "cred";
+
+ Properties props = appender.buildEnvProperties();
+ assertEquals(4, props.size());
+ assertEquals(appender.initialContextFactoryName, props
+ .getProperty(Context.INITIAL_CONTEXT_FACTORY));
+ assertEquals(null, props.getProperty(Context.PROVIDER_URL));
+ assertEquals(appender.urlPkgPrefixes, props
+ .getProperty(Context.URL_PKG_PREFIXES));
+ assertEquals(appender.securityPrincipalName, props
+ .getProperty(Context.SECURITY_PRINCIPAL));
+ assertEquals(appender.securityCredentials, props
+ .getProperty(Context.SECURITY_CREDENTIALS));
+
+ assertEquals(1, context.getStatusManager().getCount());
+ }
+
+ public void testBuildEnvPropertiesWithNullCredentials() {
+ appender.initialContextFactoryName = "icfn";
+ appender.providerURL = "url";
+ appender.urlPkgPrefixes = "pkgPref";
+ appender.securityPrincipalName = "user";
+ appender.securityCredentials = null;
+
+ Properties props = appender.buildEnvProperties();
+ assertEquals(4, props.size());
+ assertEquals(appender.initialContextFactoryName, props
+ .getProperty(Context.INITIAL_CONTEXT_FACTORY));
+ assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
+ assertEquals(appender.urlPkgPrefixes, props
+ .getProperty(Context.URL_PKG_PREFIXES));
+ assertEquals(appender.securityPrincipalName, props
+ .getProperty(Context.SECURITY_PRINCIPAL));
+ assertEquals(null, props
+ .getProperty(Context.SECURITY_CREDENTIALS));
+
+ assertEquals(1, context.getStatusManager().getCount());
+ }
+
+ public void testBuildEnvPropertiesWithPkgNull() {
+ appender.initialContextFactoryName = "icfn";
+ appender.providerURL = "url";
+ appender.urlPkgPrefixes = null;
+ appender.securityPrincipalName = "user";
+ appender.securityCredentials = "cred";
+
+ Properties props = appender.buildEnvProperties();
+ assertEquals(4, props.size());
+ assertEquals(appender.initialContextFactoryName, props
+ .getProperty(Context.INITIAL_CONTEXT_FACTORY));
+ assertEquals(appender.providerURL, props.getProperty(Context.PROVIDER_URL));
+ assertEquals(null, props
+ .getProperty(Context.URL_PKG_PREFIXES));
+ assertEquals(appender.securityPrincipalName, props
+ .getProperty(Context.SECURITY_PRINCIPAL));
+ assertEquals(appender.securityCredentials, props
+ .getProperty(Context.SECURITY_CREDENTIALS));
+
+ assertEquals(0, context.getStatusManager().getCount());
+ }
+
+ public void testStartMinimalInfo() {
+ //let's leave only what's in the setup()
+ //method, minus the providerURL
+ appender.providerURL = null;
+ appender.start();
+
+ assertTrue(appender.isStarted());
+
+ try {
+ assertEquals(appender.queueBindingName, appender.queueSender.getQueue().getQueueName());
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ public void testStartUserPass() {
+ appender.userName = "";
+ appender.password = "";
+
+ appender.start();
+
+ assertTrue(appender.isStarted());
+
+ try {
+ assertEquals(appender.queueBindingName, appender.queueSender.getQueue().getQueueName());
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ public void testStartFails() {
+ appender.queueBindingName = null;
+
+ appender.start();
+
+ assertFalse(appender.isStarted());
+ }
+
+ private LoggingEvent createLoggingEvent() {
+ LoggingEvent le = new LoggingEvent();
+ le.setLevel(Level.DEBUG);
+ le.setMessage("test message");
+ le.setTimeStamp(System.currentTimeMillis());
+ le.setThreadName(Thread.currentThread().getName());
+ return le;
+ }
+}
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java Thu Jan 11 14:36:49 2007
@@ -167,7 +167,7 @@
public void testStartMinimalInfo() {
//let's leave only what's in the setup()
//method, minus the providerURL
- appender.providerURL = "url";
+ appender.providerURL = null;
appender.start();
assertTrue(appender.isStarted());
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueue.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueue.java Thu Jan 11 14:36:49 2007
@@ -0,0 +1,18 @@
+package ch.qos.logback.classic.net.mock;
+
+import javax.jms.JMSException;
+import javax.jms.Queue;
+
+public class MockQueue implements Queue {
+
+ String name;
+
+ public MockQueue(String name) {
+ this.name = name;
+ }
+
+ public String getQueueName() throws JMSException {
+ return name;
+ }
+
+}
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueueConnection.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueueConnection.java Thu Jan 11 14:36:49 2007
@@ -0,0 +1,83 @@
+package ch.qos.logback.classic.net.mock;
+
+import javax.jms.ConnectionConsumer;
+import javax.jms.ConnectionMetaData;
+import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueSession;
+import javax.jms.ServerSessionPool;
+import javax.jms.Session;
+import javax.jms.Topic;
+
+public class MockQueueConnection implements QueueConnection {
+
+ MockQueueSession session = new MockQueueSession();
+
+ public QueueSession createQueueSession(boolean arg0, int arg1) throws JMSException {
+ return session;
+ }
+
+ public ConnectionConsumer createConnectionConsumer(Queue arg0, String arg1, ServerSessionPool arg2, int arg3) throws JMSException {
+
+ return null;
+ }
+
+ public void close() throws JMSException {
+
+
+ }
+
+ public ConnectionConsumer createConnectionConsumer(Destination arg0, String arg1, ServerSessionPool arg2, int arg3) throws JMSException {
+
+ return null;
+ }
+
+ public ConnectionConsumer createDurableConnectionConsumer(Topic arg0, String arg1, String arg2, ServerSessionPool arg3, int arg4) throws JMSException {
+
+ return null;
+ }
+
+ public Session createSession(boolean arg0, int arg1) throws JMSException {
+
+ return null;
+ }
+
+ public String getClientID() throws JMSException {
+
+ return null;
+ }
+
+ public ExceptionListener getExceptionListener() throws JMSException {
+
+ return null;
+ }
+
+ public ConnectionMetaData getMetaData() throws JMSException {
+
+ return null;
+ }
+
+ public void setClientID(String arg0) throws JMSException {
+
+
+ }
+
+ public void setExceptionListener(ExceptionListener arg0) throws JMSException {
+
+
+ }
+
+ public void start() throws JMSException {
+
+
+ }
+
+ public void stop() throws JMSException {
+
+
+ }
+
+}
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueueConnectionFactory.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueueConnectionFactory.java Thu Jan 11 14:36:49 2007
@@ -0,0 +1,29 @@
+package ch.qos.logback.classic.net.mock;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+
+public class MockQueueConnectionFactory implements QueueConnectionFactory {
+
+ MockQueueConnection cnx = new MockQueueConnection();
+
+ public QueueConnection createQueueConnection() throws JMSException {
+ return cnx;
+ }
+
+ public QueueConnection createQueueConnection(String user, String pass) throws JMSException {
+
+ return cnx;
+ }
+
+ public Connection createConnection() throws JMSException {
+ return null;
+ }
+
+ public Connection createConnection(String arg0, String arg1) throws JMSException {
+ return null;
+ }
+
+}
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueueSender.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueueSender.java Thu Jan 11 14:36:49 2007
@@ -0,0 +1,121 @@
+package ch.qos.logback.classic.net.mock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Queue;
+import javax.jms.QueueSender;
+
+public class MockQueueSender implements QueueSender {
+
+ List<Message> messageList = new ArrayList<Message>();
+ Queue queue;
+
+ public MockQueueSender(Queue queue) {
+ this.queue = queue;
+ }
+
+ public List<Message> getMessageList() {
+ return messageList;
+ }
+
+ public Queue getQueue() throws JMSException {
+ return queue;
+ }
+
+ public void send(Message message) throws JMSException {
+ messageList.add(message);
+
+ }
+
+ public void send(Queue arg0, Message arg1) throws JMSException {
+
+
+ }
+
+ public void send(Message arg0, int arg1, int arg2, long arg3) throws JMSException {
+
+
+ }
+
+ public void send(Queue arg0, Message arg1, int arg2, int arg3, long arg4) throws JMSException {
+
+
+ }
+
+ public void close() throws JMSException {
+
+
+ }
+
+ public int getDeliveryMode() throws JMSException {
+
+ return 0;
+ }
+
+ public Destination getDestination() throws JMSException {
+
+ return null;
+ }
+
+ public boolean getDisableMessageID() throws JMSException {
+
+ return false;
+ }
+
+ public boolean getDisableMessageTimestamp() throws JMSException {
+
+ return false;
+ }
+
+ public int getPriority() throws JMSException {
+
+ return 0;
+ }
+
+ public long getTimeToLive() throws JMSException {
+
+ return 0;
+ }
+
+ public void send(Destination arg0, Message arg1) throws JMSException {
+
+
+ }
+
+ public void send(Destination arg0, Message arg1, int arg2, int arg3, long arg4) throws JMSException {
+
+
+ }
+
+ public void setDeliveryMode(int arg0) throws JMSException {
+
+
+ }
+
+ public void setDisableMessageID(boolean arg0) throws JMSException {
+
+
+ }
+
+ public void setDisableMessageTimestamp(boolean arg0) throws JMSException {
+
+
+ }
+
+ public void setPriority(int arg0) throws JMSException {
+
+
+ }
+
+ public void setTimeToLive(long arg0) throws JMSException {
+
+
+ }
+
+
+
+}
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueueSession.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockQueueSession.java Thu Jan 11 14:36:49 2007
@@ -0,0 +1,195 @@
+package ch.qos.logback.classic.net.mock;
+
+import java.io.Serializable;
+
+import javax.jms.BytesMessage;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.StreamMessage;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicSubscriber;
+
+public class MockQueueSession implements QueueSession {
+
+ public ObjectMessage createObjectMessage() throws JMSException {
+ return new MockObjectMessage();
+ }
+
+ public QueueSender createSender(Queue queue) throws JMSException {
+ if (queue == null) {
+ return null;
+ }
+ return new MockQueueSender(queue);
+ }
+
+ public QueueBrowser createBrowser(Queue arg0) throws JMSException {
+
+ return null;
+ }
+
+ public QueueBrowser createBrowser(Queue arg0, String arg1) throws JMSException {
+
+ return null;
+ }
+
+ public Queue createQueue(String arg0) throws JMSException {
+
+ return null;
+ }
+
+ public QueueReceiver createReceiver(Queue arg0) throws JMSException {
+
+ return null;
+ }
+
+ public QueueReceiver createReceiver(Queue arg0, String arg1) throws JMSException {
+
+ return null;
+ }
+
+ public TemporaryQueue createTemporaryQueue() throws JMSException {
+
+ return null;
+ }
+
+ public void close() throws JMSException {
+
+
+ }
+
+ public void commit() throws JMSException {
+
+
+ }
+
+ public BytesMessage createBytesMessage() throws JMSException {
+
+ return null;
+ }
+
+ public MessageConsumer createConsumer(Destination arg0) throws JMSException {
+
+ return null;
+ }
+
+ public MessageConsumer createConsumer(Destination arg0, String arg1) throws JMSException {
+
+ return null;
+ }
+
+ public MessageConsumer createConsumer(Destination arg0, String arg1, boolean arg2) throws JMSException {
+
+ return null;
+ }
+
+ public TopicSubscriber createDurableSubscriber(Topic arg0, String arg1) throws JMSException {
+
+ return null;
+ }
+
+ public TopicSubscriber createDurableSubscriber(Topic arg0, String arg1, String arg2, boolean arg3) throws JMSException {
+
+ return null;
+ }
+
+ public MapMessage createMapMessage() throws JMSException {
+
+ return null;
+ }
+
+ public Message createMessage() throws JMSException {
+
+ return null;
+ }
+
+ public ObjectMessage createObjectMessage(Serializable arg0) throws JMSException {
+
+ return null;
+ }
+
+ public MessageProducer createProducer(Destination arg0) throws JMSException {
+
+ return null;
+ }
+
+ public StreamMessage createStreamMessage() throws JMSException {
+
+ return null;
+ }
+
+ public TemporaryTopic createTemporaryTopic() throws JMSException {
+
+ return null;
+ }
+
+ public TextMessage createTextMessage() throws JMSException {
+
+ return null;
+ }
+
+ public TextMessage createTextMessage(String arg0) throws JMSException {
+
+ return null;
+ }
+
+ public Topic createTopic(String arg0) throws JMSException {
+
+ return null;
+ }
+
+ public int getAcknowledgeMode() throws JMSException {
+
+ return 0;
+ }
+
+ public MessageListener getMessageListener() throws JMSException {
+
+ return null;
+ }
+
+ public boolean getTransacted() throws JMSException {
+
+ return false;
+ }
+
+ public void recover() throws JMSException {
+
+
+ }
+
+ public void rollback() throws JMSException {
+
+
+ }
+
+ public void run() {
+
+
+ }
+
+ public void setMessageListener(MessageListener arg0) throws JMSException {
+
+
+ }
+
+ public void unsubscribe(String arg0) throws JMSException {
+
+
+ }
+
+
+}
1
0