svn commit: r862 - in logback/trunk: logback-examples/src/main/java/chapter1 logback-site/src/site/xdocTemplates

Author: ceki Date: Thu Nov 2 22:57:04 2006 New Revision: 862 Modified: logback/trunk/logback-examples/src/main/java/chapter1/Bar.java logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld1.java logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld2.java logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld3.java logback/trunk/logback-examples/src/main/java/chapter1/MyApp.java logback/trunk/logback-examples/src/main/java/chapter1/MyAppWithConfigFile.java logback/trunk/logback-site/src/site/xdocTemplates/shortIntro.xml Log: ongoing work Modified: logback/trunk/logback-examples/src/main/java/chapter1/Bar.java ============================================================================== --- logback/trunk/logback-examples/src/main/java/chapter1/Bar.java (original) +++ logback/trunk/logback-examples/src/main/java/chapter1/Bar.java Thu Nov 2 22:57:04 2006 @@ -1,11 +1,21 @@ +/** + * Logback: the generic, reliable, fast and flexible logging framework. + * + * 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 chapter1; import org.slf4j.Logger; import org.slf4j.LoggerFactory; class Bar { - Logger logger = LoggerFactory.getLogger(Bar.class); - public void doIt() { - logger.debug("doing my job"); - } + Logger logger = LoggerFactory.getLogger(Bar.class); + + public void doIt() { + logger.debug("doing my job"); + } } \ No newline at end of file Modified: logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld1.java ============================================================================== --- logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld1.java (original) +++ logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld1.java Thu Nov 2 22:57:04 2006 @@ -1,3 +1,12 @@ +/** + * Logback: the generic, reliable, fast and flexible logging framework. + * + * 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 chapter1; import org.slf4j.Logger; @@ -5,9 +14,9 @@ public class HelloWorld1 { - public static void main(String[] args) { + public static void main(String[] args) { Logger logger = LoggerFactory.getLogger("chapter1.HelloWorld1"); - logger.debug("Hello world."); - } + logger.debug("Hello world."); + } } Modified: logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld2.java ============================================================================== --- logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld2.java (original) +++ logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld2.java Thu Nov 2 22:57:04 2006 @@ -1,3 +1,12 @@ +/** + * Logback: the generic, reliable, fast and flexible logging framework. + * + * 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 chapter1; import org.slf4j.Logger; @@ -7,9 +16,9 @@ public class HelloWorld2 { - public static void main(String[] args) { + public static void main(String[] args) { Logger logger = LoggerFactory.getLogger("chapter1.HelloWorld2"); - logger.debug("Hello world."); - LoggerStatusPrinter.printStatusInDefaultContext(); - } + logger.debug("Hello world."); + LoggerStatusPrinter.printStatusInDefaultContext(); + } } Modified: logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld3.java ============================================================================== --- logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld3.java (original) +++ logback/trunk/logback-examples/src/main/java/chapter1/HelloWorld3.java Thu Nov 2 22:57:04 2006 @@ -1,3 +1,12 @@ +/** + * Logback: the generic, reliable, fast and flexible logging framework. + * + * 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 chapter1; import org.slf4j.Logger; @@ -11,8 +20,8 @@ public static void main(String[] args) { Logger logger = LoggerFactory.getLogger("chapter1.HelloWorld3"); - BasicConfigurator.configureDefaultContext(); - logger.debug("Hello world."); - LoggerStatusPrinter.printStatusInDefaultContext(); - } + BasicConfigurator.configureDefaultContext(); + logger.debug("Hello world."); + LoggerStatusPrinter.printStatusInDefaultContext(); + } } Modified: logback/trunk/logback-examples/src/main/java/chapter1/MyApp.java ============================================================================== --- logback/trunk/logback-examples/src/main/java/chapter1/MyApp.java (original) +++ logback/trunk/logback-examples/src/main/java/chapter1/MyApp.java Thu Nov 2 22:57:04 2006 @@ -1,3 +1,12 @@ +/** + * Logback: the generic, reliable, fast and flexible logging framework. + * + * 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 chapter1; // Import SLF4J classes. @@ -8,15 +17,15 @@ public class MyApp { - public static void main(String[] args) { - // Set up a simple configuration that logs on the console. - BasicConfigurator.configureDefaultContext(); - - Logger logger = LoggerFactory.getLogger(MyApp.class); - - logger.info("Entering application."); - Bar bar = new Bar(); - bar.doIt(); - logger.info("Exiting application."); - } + public static void main(String[] args) { + // Set up a simple configuration that logs on the console. + BasicConfigurator.configureDefaultContext(); + + Logger logger = LoggerFactory.getLogger(MyApp.class); + + logger.info("Entering application."); + Bar bar = new Bar(); + bar.doIt(); + logger.info("Exiting application."); + } } Modified: logback/trunk/logback-examples/src/main/java/chapter1/MyAppWithConfigFile.java ============================================================================== --- logback/trunk/logback-examples/src/main/java/chapter1/MyAppWithConfigFile.java (original) +++ logback/trunk/logback-examples/src/main/java/chapter1/MyAppWithConfigFile.java Thu Nov 2 22:57:04 2006 @@ -1,3 +1,12 @@ +/** + * Logback: the generic, reliable, fast and flexible logging framework. + * + * 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 chapter1; //Import SLF4J classes. 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 Nov 2 22:57:04 2006 @@ -107,21 +107,6 @@ <p>Let us now begin experimenting with logback.</p> - <p>In order to facilitate running the the examples in this - introduction, we have placed the required jar files in the - <em>$LOGBACK_HOME/logback-examples/lib</em> directory. Assuming - your current directory is $LOGBACK_HOME/logback-examples, where - $LOGBACK_HOME is the directory you've installed logback, you can - start launch the first example application, - <em>chapter1.HelloWord1</em> with the following command: - </p> - <div class="source"><pre>java -cp lib/slf4j-api-1.1.0-beta0.jar;../logback-core-${version}.jar;\ - ../logback-classic-${version}.jar;logback-examples-${version}.jar\ - chapter1.HelloWorld1</pre></div> - - - - <em>Example 1.1: Basic template for logging (<a href="xref/chapter1/HelloWorld1.html">logback-examples/src/main/java/chapter1/HelloWorld1.java</a>)</em> <div class="source"><pre>package chapter1; @@ -169,11 +154,17 @@ </p> - <p> - Once you're in the <em>logback-examples/classes</em> directory of the logback distribution, you can run this class with the command: - </p> - - <div class="source"><pre>java chapter1.HelloWorld1</pre></div> + <p>In order to facilitate running the the examples in this + introduction, we have placed the required slf4j-api.jar file in + the <em>$LOGBACK_HOME/logback-examples/lib</em> + directory. Assuming your current directory is + $LOGBACK_HOME/logback-examples, where $LOGBACK_HOME is the + directory you've installed logback, you can launch the first + sample application, <em>chapter1.HelloWord1</em> with the command: + </p> + <div class="source"><pre>java -cp lib/slf4j-api-1.1.0-beta0.jar;../logback-core-${version}.jar;\ + ../logback-classic-${version}.jar;logback-examples-${version}.jar\ + chapter1.HelloWorld1</pre></div> <p> Suprisingly enough, launching the <code>HelloWorld1</code> @@ -192,7 +183,7 @@ class. </p> -<em>Example 1.2: Printing Logger Status (logback-examples/src/main/java/chapter1/HelloWorld2.java)</em> +<em>Example 1.2: Printing Logger Status (<a href="xref/chapter1/HelloWorld2.html">logback-examples/src/main/java/chapter1/HelloWorld2.java</a>)</em> <div class="source"><pre>package chapter1; import org.slf4j.Logger; @@ -216,23 +207,22 @@ context [default] for logger [chapter1.HelloWorld2].</pre></div> - <!-- ========= CEKI: STOPPED HERE =================== --> - <p> Logback complains that no appenders were configured for the - default context. An <code>Appender</code> is a class that can be seen as an - output destination. Appenders exist for many different - destinations including the console, files, Syslog, Socket, JMS and many more. Users - can also easily create their own Appenders for any specific - situation. + default context. An <code>Appender</code> is a class that can be + seen as an output destination. Appenders exist for many different + destinations including the console, files, Syslog, Socket, JMS and + many more. Users can also easily create their own Appenders as + appropriate for their specific situation. </p> <p> - Configuring logback can be done in different ways. The - simplest but least flexible way is by calling the - <code>BasicConfigurator</code> class, like in the following code snippet. + Configuring logback can be done in various ways. The simplest but + least flexible way is by calling the + <code>BasicConfigurator</code> class, like in the following code + snippet. </p> - <em>Example 1.3: Configuring before logging (logback-examples/src/main/java/chapter1/HelloWorld3.java)</em> + <em>Example 1.3: Configuring before logging (<a href="xref/chapter1/HelloWorld3.html">logback-examples/src/main/java/chapter1/HelloWorld3.java)</a></em> <div class="source"><pre>package chapter1; import org.slf4j.Logger; @@ -262,17 +252,20 @@ <div class="source"><pre>0 [main] DEBUG chapter1.HelloWorld3 - Hello world.</pre></div> <p> - This example is rather simple. However, actual logging in a larger - application would not be that different. The general pattern logging statements - will barely change. Only the configuration process will be - different since you don't need (nor should) configure the - logging context in each and every class that will require - logging. As you will see later on in this document, configuring logback can be done - in different flexible and powerfull manners. - As well, the <code>LoggerStatusPrinter</code> will certainly not be - used after all the logging statements. + This example is rather simple. However, actual logging in a + larger application would not be much different. The general + pattern logging statements will barely change. Only the + configuration process will be different since you don't need + (nor should) configure the logging context in each and every + class that requires logging. As you will see later on in this + document, configuring logback can be done in different flexible + and powerfull ways. Note that, normally, you won't need to + invoke <code>LoggerStatusPrinter</code> after your log + statements. </p> + <!-- ========= CEKI: STOPPED HERE =================== --> + <p> These are the three steps that are required to enable logging in your application. </p>
participants (1)
-
noreply.ceki@qos.ch