ceki 01/10/02 14:53:05
Modified: src/docbook configuration.xml
Log:
minor additions
Revision Changes Path
1.11 +80 -47 jakarta-log4j/src/docbook/configuration.xml
Index: configuration.xml
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/docbook/configuration.xml,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- configuration.xml 2001/10/02 06:36:45 1.10
+++ configuration.xml 2001/10/02 21:53:05 1.11
@@ -20,23 +20,32 @@
configuration files. Currently, configuration files can be
written in XML or in Java properties (key=value) format.</para>
- <para>Let us give a taste of how this is done with the help of an
- imaginary application <classname>MyApp</classname> that uses log4j.
+ <para>In the following sections we will give examples of configuring
+ log4j using first <classname>BasicConfigurator</classname> and then
+ both the <classname>PropertyConfigurator</classname> and
+ <classname>DOMConfigurator</classname>.
</para>
-
- <para>
- <programlisting>
+ <sect1>
+ <title>Simplest approach using
+ <classname>BasicConfigurator</classname></title>
+
+ <para>Let us give a taste of how this is done with the help of an
+ imaginary application <classname>MyApp</classname> that uses log4j.
+ </para>
+
+ <para>
+ <programlisting>
import com.foo.Bar;
// Import log4j classes.
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
- public class MyApp {
+ public class MyApp1 {
// Define a static category variable so that it references the
- // Logger instance named "MyApp".
- static Logger logger = Logger.getLogger(MyApp.class);
+ // Logger instance named "MyApp1".
+ static Logger logger = Logger.getLogger(MyApp1.class);
public static void main(String[] args) {
@@ -49,22 +58,22 @@
logger.info("Exiting application.");
}
}
- </programlisting>
- </para>
-
-
- <para><classname>MyApp</classname> begins by importing log4j related
- classes. It then defines a static logger variable with the name
- <classname>MyApp</classname> which happens to be the fully
- qualified name of the class.
- </para>
+ </programlisting>
+ </para>
- <para><classname>MyApp</classname> uses the
- <classname>Bar</classname> class defined in the package
- <classname>com.foo</classname>.</para>
- <para>
- <programlisting>
+ <para><classname>MyApp1</classname> begins by importing log4j related
+ classes. It then defines a static logger variable with the name
+ <classname>MyApp</classname> which happens to be the fully
+ qualified name of the class.
+ </para>
+
+ <para><classname>MyApp1</classname> uses the
+ <classname>Bar</classname> class defined in the package
+ <classname>com.foo</classname>.</para>
+
+ <para>
+ <programlisting>
<emphasis role="bold">package com.foo;</emphasis>
import org.apache.log4j.Logger;
@@ -75,8 +84,8 @@
logger.debug("Did it again!");
}
}
- </programlisting>
- </para>
+ </programlisting>
+ </para>
<para>The invocation of the <ulink
url="../api/org/apache/log4j/BasicConfigurator.html#configure()">BasicConfigurator.configure</ulink>
@@ -94,13 +103,13 @@
<para>The output of MyApp is:
<screen>
-0 [main] INFO MyApp - Entering application.
+0 [main] INFO MyApp1 - Entering application.
36 [main] DEBUG com.foo.Bar - Did it again!
-51 [main] INFO MyApp - Exiting application.
+51 [main] INFO MyApp1 - Exiting application.
</screen>
</para>
- <para>The figure below depicts the object diagram of <classname>MyApp</classname>
+ <para>The figure below depicts the object diagram of <classname>MyApp1</classname>
after just having called the <classname>BasicConfigurator.configure</classname>
method. </para>
@@ -117,18 +126,18 @@
footprint.
</para>
- <para>The <classname>MyApp</classname> class configures log4j by invoking
+ <para>The <classname>MyApp1</classname> class configures log4j by invoking
<classname>BasicConfigurator.configure</classname> method. Other classes
only need to import the <classname>org.apache.log4j.Logger</classname>
class, retrieve the loggers they wish to use, and log away.
- </para>
-
- <sect1>
+ </para>
+ </sect1>
+ <sect1>
<title><classname>BasicConfigurator</classname> equivalent using
<classname>PropertyConfigurator</classname></title>
<para>The previous example always outputs the same log information.
- Fortunately, it is easy to modify <classname>MyApp</classname> so that the
+ Fortunately, it is easy to modify <classname>MyApp1</classname> so that the
log output can be controlled at run-time. Here is a slightly
modified version.
</para>
@@ -141,9 +150,9 @@
import org.apache.log4j.Logger;
<emphasis role="strong">import org.apache.log4j.PropertyConfigurator;</emphasis>
- public class MyApp {
+ public class MyApp2 {
- static Logger cat = Logger.getInstance(MyApp.class.getName());
+ static Logger cat = Logger.getInstance(MyApp2.class.getName());
public static void main(String[] args) {
@@ -160,9 +169,9 @@
</programlisting>
</para>
- <para>This version of <classname>MyApp</classname> instructs
- <classname>PropertyConfigurator</classname> to parse a configuration file
- and set up logging accordingly.
+ <para><classname>MyApp2</classname> instructs
+ <classname>PropertyConfigurator</classname> to parse a
+ configuration file and set up logging accordingly.
</para>
<para>Here is a sample configuration file that results in exactly
@@ -204,9 +213,9 @@
import org.apache.log4j.Logger;
<emphasis role="strong">import org.apache.log4j.xml.DOMConfigurator;</emphasis>
- public class MyApp {
+ public class MyApp3 {
- static Logger cat = Logger.getInstance(MyApp.class.getName());
+ static Logger cat = Logger.getInstance(MyApp3.class.getName());
public static void main(String[] args) {
@@ -255,9 +264,11 @@
<title>Filtering by logger level</title>
<para>Suppose we are no longer interested in seeing the output of
- any component belonging to the <classname>com.foo</classname> package. The
- following configuration file shows one possible way of achieving
- this.
+ any component belonging to the <classname>com.foo</classname>
+ package. The following configuration file shows one efficient
+ way of achieving this. In <xref linkend="thresholdFiltering"/>
+ and <xref linkend="configuringFilters"/> and we discuss
+ alternate was of achieving a similar effect.
</para>
<para>
@@ -386,7 +397,7 @@
</sect1>
<sect1>
- <title>Multiple Appenders using <classname>DOMConfigurator</classname>
+ <title>Multiple Appenders using <classname>DOMConfigurator</classname></title>
<para>
<example><title>XML equivalent configuration file</title>
<screen>
@@ -423,9 +434,7 @@
</para>
</sect1>
- </sect1>
-
- <sect1>
+ <sect1 id="thresholdFiltering">
<title>Directing log output to different appenders depending on level</title>
<para>Setting the <emphasis role="bold">Threshold</emphasis> option
@@ -450,6 +459,30 @@
<para>See sort4.lcf for an example threshold configuration. </para>
+ <programlisting>
+
+# Set root logger priority to DEBUG and its only appender to A1.
+log4j.rootLogger=DEBUG, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+log4j.appender.A1.Threshold=INFO
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
+ </programlisting>
+
+ <para>Running <classname>MyApp2</classname> with the this
+ configuration scripts yields the following output on the screen.
+ </para>
+
+ <screen>
+0 [main] INFO MyApp - Entering application.
+51 [main] INFO MyApp - Exiting application.
+ </screen>
+
<para>If you must filter events by exact priority match, then you can
attach a PriorityMatchFilter to any appender to filter out logging
events by exact priority match.</para>
@@ -475,7 +508,7 @@
<para>Give an example</para>
</sect1>
- <sect1>
+ <sect1 id="configuringFilters">
<title>Filters</title>
<para></para>
</sect1>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]