[logback-dev] svn commit: r656 - in logback/trunk/logback-classic/src/main/java: ch/qos/logback/classic org/slf4j

noreply.seb at qos.ch noreply.seb at qos.ch
Tue Oct 10 16:17:05 CEST 2006


Author: seb
Date: Tue Oct 10 16:17:05 2006
New Revision: 656

Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
   logback/trunk/logback-classic/src/main/java/org/slf4j/LoggerFactory.java

Log:
Added a default initialization procedure to the LoggerFactory. 
Reformatted LoggerContext code.

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java	Tue Oct 10 16:17:05 2006
@@ -10,35 +10,40 @@
 
 package ch.qos.logback.classic;
 
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Hashtable;
 
 import org.slf4j.ILoggerFactory;
 
+import ch.qos.logback.classic.joran.JoranConfigurator;
 import ch.qos.logback.classic.spi.LoggerContextRemoteView;
 import ch.qos.logback.core.ContextBase;
 import ch.qos.logback.core.CoreGlobal;
 import ch.qos.logback.core.status.ErrorStatus;
-
+import ch.qos.logback.core.util.Loader;
+import ch.qos.logback.core.util.StatusPrinter;
 
 /**
  * @author ceki
  */
 public class LoggerContext extends ContextBase implements ILoggerFactory {
 
-	public static final String ROOT_NAME = "root";
-	
+  public static final String ROOT_NAME = "root";
+
   final Logger root;
   private int size;
   private int noAppenderWarning = 0;
-  
-  // We want loggerCache to be synchronized so Hashtable is a good choice. In practice, it 
-  // performs a little faster than the map returned by Collections.synchronizedMap at the 
+
+  // We want loggerCache to be synchronized so Hashtable is a good choice. In
+  // practice, it
+  // performs a little faster than the map returned by
+  // Collections.synchronizedMap at the
   // cost of a very slightly higher memory footprint.
   private Hashtable<String, Logger> loggerCache;
 
-	LoggerContextRemoteView loggerContextRemoteView;
-	
+  LoggerContextRemoteView loggerContextRemoteView;
+
   public LoggerContext() {
     super();
     this.loggerCache = new Hashtable<String, Logger>();
@@ -49,38 +54,39 @@
     putObject(CoreGlobal.EVALUATOR_MAP, new HashMap());
     size = 1;
   }
-  
+
   /**
-   * A new instance of LoggerContextRemoteView needs to be created each time
-   * the name or propertyMap (including keys or values) changes.
+   * A new instance of LoggerContextRemoteView needs to be created each time the
+   * name or propertyMap (including keys or values) changes.
    */
   private void syncRemoteView() {
-  	loggerContextRemoteView = new LoggerContextRemoteView(this);
-  	for(Logger logger : loggerCache.values()) {
-  		logger.buildRemoteView();
-  	}
+    loggerContextRemoteView = new LoggerContextRemoteView(this);
+    for (Logger logger : loggerCache.values()) {
+      logger.buildRemoteView();
+    }
   }
-  
+
   @Override
   public void setName(String name) {
-	  	super.setName(name);
-	    syncRemoteView();
+    super.setName(name);
+    syncRemoteView();
   }
 
   public final Logger getLogger(final Class clazz) {
     return getLogger(clazz.getName());
   }
-  
+
   public final Logger getLogger(final String name) {
 
-    //if we are asking for the root logger, then let us return it without wasting time
+    // if we are asking for the root logger, then let us return it without
+    // wasting time
     if (ROOT_NAME.equalsIgnoreCase(name)) {
-    	return root;
+      return root;
     }
-    
+
     int i = 0;
     Logger logger = root;
-    
+
     // check if the desired logger exists, if it does, return it
     // without further ado.
     Logger childLogger = (Logger) loggerCache.get(name);
@@ -125,23 +131,25 @@
   }
 
   /**
-   * Check if the named logger exists in the hierarchy. If so return
-   * its reference, otherwise returns <code>null</code>.
-   *
-   * @param name the name of the logger to search for.
+   * Check if the named logger exists in the hierarchy. If so return its
+   * reference, otherwise returns <code>null</code>.
+   * 
+   * @param name
+   *          the name of the logger to search for.
    */
   Logger exists(String name) {
     return (Logger) loggerCache.get(name);
   }
-  
+
   final void noAppenderDefinedWarning(final Logger logger) {
-  	 if (noAppenderWarning++ == 0) {
-  	      getStatusManager().add(new ErrorStatus(
-	        "No appenders present in context ["+ getName() +"] for logger [" + logger.getName() + "].", logger));
-  	 }
+    if (noAppenderWarning++ == 0) {
+      getStatusManager().add(
+          new ErrorStatus("No appenders present in context [" + getName()
+              + "] for logger [" + logger.getName() + "].", logger));
+    }
   }
-  
+
   public LoggerContextRemoteView getLoggerContextRemoteView() {
-  	return loggerContextRemoteView;
+    return loggerContextRemoteView;
   }
 }

Modified: logback/trunk/logback-classic/src/main/java/org/slf4j/LoggerFactory.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/org/slf4j/LoggerFactory.java	(original)
+++ logback/trunk/logback-classic/src/main/java/org/slf4j/LoggerFactory.java	Tue Oct 10 16:17:05 2006
@@ -32,9 +32,16 @@
  */
 package org.slf4j;
 
+import java.net.URL;
+
 import org.slf4j.impl.StaticLoggerBinder;
 import org.slf4j.impl.Util;
 
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.util.Loader;
+import ch.qos.logback.core.util.StatusPrinter;
+
 /**
  * The <code>LoggerFactory</code> is a utility class producing Loggers for
  * various logging APIs, most notably for NLOG4J and JDK 1.4 logging. Other
@@ -63,6 +70,16 @@
   static {
     try { 
       loggerFactory = StaticLoggerBinder.SINGLETON.getLoggerFactory();
+      URL url = Loader.getResource("logback-classic.xml");
+      System.out.println("URL = " + url);
+      if (url != null) {
+        JoranConfigurator configurator = new JoranConfigurator();
+        configurator.setContext((Context)loggerFactory);
+        configurator.doConfigure(url);
+        StatusPrinter.print((Context)loggerFactory);
+      } else {
+        //TODO basic configuration??
+      }
     } catch (Exception e) {
       // we should never get here
       Util.reportFailure("Failed to instantiate logger ["



More information about the logback-dev mailing list