[logback-dev] svn commit: r637 - in logback/trunk: logback-core/examples/src/joran/helloWorld logback-core/examples/src/joran/implicit logback-core/examples/src/joran/newRule logback-site/src/site/xdocTemplates
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Sun Oct 8 19:57:35 CEST 2006
Author: ceki
Date: Sun Oct 8 19:57:35 2006
New Revision: 637
Modified:
logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorld.java
logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorldAction.java
logback/trunk/logback-core/examples/src/joran/implicit/PrintMe.java
logback/trunk/logback-core/examples/src/joran/newRule/NewRuleCalculator.java
logback/trunk/logback-site/src/site/xdocTemplates/joran.xml
Log:
minor modifications
Modified: logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorld.java
==============================================================================
--- logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorld.java (original)
+++ logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorld.java Sun Oct 8 19:57:35 2006
@@ -1,15 +1,26 @@
+/**
+ * Logback: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
package joran.helloWorld;
-
-
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.joran.spi.ExecutionContext;
import ch.qos.logback.core.joran.spi.Interpreter;
import ch.qos.logback.core.joran.spi.Pattern;
import ch.qos.logback.core.joran.spi.RuleStore;
import ch.qos.logback.core.joran.spi.SimpleRuleStore;
+import ch.qos.logback.core.util.StatusPrinter;
/**
@@ -25,20 +36,23 @@
java joran.helloWorld.HelloWorld examples/src/joran/helloWorld/hello.xml
</pre>
*
- * @author Ceki
+ * @author Ceki Gulcu
*/
public class HelloWorld {
public static void main(String[] args) throws Exception {
// Create a simple rule store where pattern and action associations will
// be kept.
- RuleStore ruleStore = new SimpleRuleStore(null);
+ Context context = new ContextBase();
+ RuleStore ruleStore = new SimpleRuleStore(context);
// Associate "hello-world" pattern with HelloWorldAction
ruleStore.addRule(new Pattern("hello-world"), new HelloWorldAction());
// Create a new Joran Interpreter and hand it our simple rule store.
Interpreter ji = new Interpreter(ruleStore);
-
+ ExecutionContext ec = ji.getExecutionContext();
+ ec.setContext(context);
+
// Create a SAX parser
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser saxParser = spf.newSAXParser();
@@ -46,5 +60,9 @@
// Parse the file given as the application's first argument and
// set the SAX ContentHandler to the Joran Interpreter we just created.
saxParser.parse(args[0], ji);
+
+ // The file has been parsed and interpreted. We now print any errors that
+ // might have occured.
+ StatusPrinter.print(context);
}
}
Modified: logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorldAction.java
==============================================================================
--- logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorldAction.java (original)
+++ logback/trunk/logback-core/examples/src/joran/helloWorld/HelloWorldAction.java Sun Oct 8 19:57:35 2006
@@ -1,3 +1,12 @@
+/**
+ * Logback: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
package joran.helloWorld;
Modified: logback/trunk/logback-core/examples/src/joran/implicit/PrintMe.java
==============================================================================
--- logback/trunk/logback-core/examples/src/joran/implicit/PrintMe.java (original)
+++ logback/trunk/logback-core/examples/src/joran/implicit/PrintMe.java Sun Oct 8 19:57:35 2006
@@ -16,6 +16,7 @@
import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.joran.spi.ExecutionContext;
import ch.qos.logback.core.joran.spi.Interpreter;
import ch.qos.logback.core.joran.spi.Pattern;
import ch.qos.logback.core.joran.spi.RuleStore;
@@ -46,7 +47,11 @@
// Create a new Joran Interpreter and hand it our simple rule store.
Interpreter ji = new Interpreter(ruleStore);
+ // set the context for the interpreter's execution context
+ ExecutionContext ec = ji.getExecutionContext();
+ ec.setContext(context);
+
// --------------------------+
// Add an implicit action. |
// --------------------------+
Modified: logback/trunk/logback-core/examples/src/joran/newRule/NewRuleCalculator.java
==============================================================================
--- logback/trunk/logback-core/examples/src/joran/newRule/NewRuleCalculator.java (original)
+++ logback/trunk/logback-core/examples/src/joran/newRule/NewRuleCalculator.java Sun Oct 8 19:57:35 2006
@@ -17,6 +17,7 @@
import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.joran.action.NewRuleAction;
+import ch.qos.logback.core.joran.spi.ExecutionContext;
import ch.qos.logback.core.joran.spi.Interpreter;
import ch.qos.logback.core.joran.spi.Pattern;
import ch.qos.logback.core.joran.spi.RuleStore;
@@ -51,7 +52,11 @@
// Create a new Joran Interpreter and hand it our simple rule store.
Interpreter ji = new Interpreter(ruleStore);
+ // set the context for the interpreter's execution context
+ ExecutionContext ec = ji.getExecutionContext();
+ ec.setContext(context);
+
// Create a SAX parser
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser saxParser = spf.newSAXParser();
Modified: logback/trunk/logback-site/src/site/xdocTemplates/joran.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/joran.xml (original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/joran.xml Sun Oct 8 19:57:35 2006
@@ -15,6 +15,26 @@
<h2>Introduction</h2>
+<p>This document is intended to serve as an introduction to Joran, a
+mature, flexible and powerful configuration framework. Many of the
+capabilities offered by logback modules are possible thanks to Joran.
+</p>
+
+<p>Joran is actually a generic configuration system which can be used
+independently of logging. To emphaises this point, I should mention
+that the logback-core module does not have a notion of loggers. In
+that sprit, many of the examples related to this tutorial, have
+nothing to do with loggers, appenders or layouts.
+</p>
+
+<p>The examples for this tutorial can be found under
+<em>LOGBACK_HOME/logback-core/examples/src/joran</em>.
+</p>
+
+<p>Missing: setup instructions</p>
+
+<h2>Historical perspective</h2>
+
<p>One of the most powerful features of the Java language is
reflection. Reflection makes it possible to configure software systems
declaratively. For example, many important properties of an EJB are
@@ -24,15 +44,15 @@
in XML format.
</p>
-<p>In log4j, logback's predecessor, DOMConfigurator that shipped with
-log4j version 1.2.x can parse configuration files written in XML. The
-DOMConfigurator is written in Java such that each time the structure
-of the configuration file changes the DOMConfigurator must be tweaked
-accordingly. Moreover, the modified code must be recompiled and
-re-deployed. Just as importantly, the code of the DOMConfigurator
-consists of loops dealing with children elements containing many
-interspersed if/else statements. One can't help but notice that that
-particular code reeks of redundancy. The <a
+<p>In log4j, logback's predecessor, <code>DOMConfigurator</code> that
+shipped with log4j version 1.2.x can parse configuration files written
+in XML. The <code>DOMConfigurator</code> was written in a way that
+forced to tweak it each time the structure of the configuration file
+changed. The modified code had to be recompiled and redeployed. Just
+as importantly, the code of the DOMConfigurator consists of loops
+dealing with children elements containing many interspersed if/else
+statements. One could not help but notice that that particular code
+reeked of redundancy. The <a
href="http://jakarta.apache.org/commons/digester/">digester
project</a> has shown that it is possible to parse XML files using
pattern matching rules. At parse time, digester will apply the rules
@@ -83,12 +103,13 @@
<p>Joran was first implemented in DOM. However, the author migrated to
SAX in order to benefit form the location information provided to the
-user, that is, to an org.w3.sax.ContentHandler. With the help of
-location information, it becomes possible to display essential error
-reports to the user which include exact line and column. This extra
-information turns out to be handy in hunting down problems.
+user, that is, to an <code>org.w3.sax.ContentHandler</code>. With the
+help of location information, it becomes possible to display essential
+error reports to the user which include exact line and column. This
+extra information turns out to be handy in hunting down problems.
</p>
+
<h2>Actions</h2>
<p>Actions extend the
More information about the logback-dev
mailing list