[LOGBack-dev] svn commit: r384 - in logback/classic/trunk/src: main/java/ch/qos/logback/classic/examples site/xdocTemplates

noreply.seb at qos.ch noreply.seb at qos.ch
Fri Jul 28 19:02:40 CEST 2006


Author: seb
Date: Fri Jul 28 19:02:39 2006
New Revision: 384

Added:
   logback/classic/trunk/src/main/java/ch/qos/logback/classic/examples/MyApp.java
Modified:
   logback/classic/trunk/src/site/xdocTemplates/shortIntro.xml
Log:
updated introduction + added a MyApp class in the examples

Added: logback/classic/trunk/src/main/java/ch/qos/logback/classic/examples/MyApp.java
==============================================================================
--- (empty file)
+++ logback/classic/trunk/src/main/java/ch/qos/logback/classic/examples/MyApp.java	Fri Jul 28 19:02:39 2006
@@ -0,0 +1,32 @@
+package ch.qos.logback.classic.examples;
+
+// Import logback classes.
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
+import ch.qos.logback.BasicConfigurator;
+
+public class MyApp {
+
+	// Define a static logger variable so that it references the
+	// Logger instance named "MyApp".
+	static Logger logger = LoggerFactory.getLogger(MyApp.class);
+
+	public static void main(String[] args) {
+
+     // Set up a simple configuration that logs on the console.
+     BasicConfigurator.configureDefaultContext();
+
+     logger.info("Entering application.");
+     Bar bar = new Bar();
+     bar.doIt();
+     logger.info("Exiting application.");
+   }
+}
+
+class Bar {
+	static Logger logger = LoggerFactory.getLogger(Bar.class);
+	public void doIt() {
+		logger.debug("doing my job");
+	}
+}
\ No newline at end of file

Modified: logback/classic/trunk/src/site/xdocTemplates/shortIntro.xml
==============================================================================
--- logback/classic/trunk/src/site/xdocTemplates/shortIntro.xml	(original)
+++ logback/classic/trunk/src/site/xdocTemplates/shortIntro.xml	Fri Jul 28 19:02:39 2006
@@ -214,7 +214,7 @@
 			the Appender and the console will output the following:
 		</p>
 <div class="source">
-Hello world.
+0    [main] DEBUG ch.qos.logback.classic.examples.BabySteps3 - Hello world.
 This status manager contains no errors.
 </div>
 		<p>
@@ -980,10 +980,101 @@
 
 		<div class="source">logger.debug("Value {} was inserted between {} and {}.", new Object[] {newVal, below, above});</div>
 
+		<div class="section">
+			<h3>Configuration</h3>
+		</div>
+		<p>
+			Inserting log requests into the application code requires 
+			a fair amount of planning and effort. Observation shows that 
+			approximately 4 percent of code is dedicated to logging. Consequently, 
+			even moderately sized applications will have thousands of logging 
+			statements embedded within their code. Given their number, it becomes 
+			imperative to manage these log statements without the need to 
+			modify them manually.
+		</p>
+		<p>
+			The logback environment is fully configurable programmatically. 
+			However, it is far more flexible to configure logback using 
+			configuration files. Currently, configuration files must be written in 
+			XML format.
+		</p>
+		<p>
+			Let us give a taste of how this is done with the help of an 
+			imaginary application MyApp that uses logback classic. 
+		</p>
+<div class="source">
+package ch.qos.logback.classic.examples;
+
+// Import logback classes.
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
+import ch.qos.logback.BasicConfigurator;
 
+public class MyApp {
 
+  // Define a static logger variable so that it references the
+  // Logger instance named "MyApp".
+  static Logger logger = LoggerFactory.getLogger(MyApp.class);
 
+  public static void main(String[] args) {
 
+    // Set up a simple configuration that logs on the console.
+    BasicConfigurator.configureDefaultContext();
+
+    logger.info("Entering application.");
+    Bar bar = new Bar();
+    bar.doIt();
+    logger.info("Exiting application.");
+  }
+}
+</div>
+		<p>
+			This class begins by defining a static logger instance variable 
+			with the name MyApp. It then uses the Bar class, defined as shown below:
+		</p>
+<div class="source">
+class Bar {
+  static Logger logger = LoggerFactory.getLogger(Bar.class);
+	
+  public void doIt() {
+    logger.debug("doing my job");
+  }
+}
+</div>
+		<p>
+			The invocation of the BasicConfigurator create, as we have seen, 
+			a simple yet sufficient logback classic setup. By default, 
+			the root Logger is assigned to Level.DEBUG.
+		</p>
+		<p>
+			The output of MyApp is:
+		</p>
+<div class="source">
+0    [main] INFO  ch.qos.logback.classic.examples.MyApp - Entering application.
+0    [main] DEBUG ch.qos.logback.classic.examples.Bar - doing my job
+0    [main] INFO  ch.qos.logback.classic.examples.MyApp - Exiting application.
+</div>
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+		
+				
 
 	</body>
 </document>



More information about the logback-dev mailing list