[LOGBack-dev] svn commit: r418 - in logback/classic/trunk: examples/src/chapter1 src/main/java/ch/qos/logback src/main/java/ch/qos/logback/classic src/main/java/ch/qos/logback/classic/joran/action src/main/java/org/slf4j/impl src/test/java/ch/qos/logback/classic src/test/java/ch/qos/logback/classic/joran
noreply.seb at qos.ch
noreply.seb at qos.ch
Tue Aug 8 21:16:34 CEST 2006
Author: seb
Date: Tue Aug 8 21:16:32 2006
New Revision: 418
Removed:
logback/classic/trunk/src/main/java/org/slf4j/impl/LBLoggerFactory.java
Modified:
logback/classic/trunk/examples/src/chapter1/MyAppWithConfigFile.java
logback/classic/trunk/src/main/java/ch/qos/logback/BasicConfigurator.java
logback/classic/trunk/src/main/java/ch/qos/logback/classic/LoggerContext.java
logback/classic/trunk/src/main/java/ch/qos/logback/classic/joran/action/RootLoggerAction.java
logback/classic/trunk/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
logback/classic/trunk/src/test/java/ch/qos/logback/classic/BasicLoggerTest.java
logback/classic/trunk/src/test/java/ch/qos/logback/classic/LoggerContextTest.java
logback/classic/trunk/src/test/java/ch/qos/logback/classic/joran/BasicJoranTest.java
Log:
- LoggerContext now implements SLF4J's ILoggerFactory, consequently we could get rid
of org.slf4j.impl.LBLoggerFactory class
- In LoggerContext, the getRootLogger method has been replaced by getLogger("root");
Modified: logback/classic/trunk/examples/src/chapter1/MyAppWithConfigFile.java
==============================================================================
--- logback/classic/trunk/examples/src/chapter1/MyAppWithConfigFile.java (original)
+++ logback/classic/trunk/examples/src/chapter1/MyAppWithConfigFile.java Tue Aug 8 21:16:32 2006
@@ -1,19 +1,21 @@
package chapter1;
//Import SLF4J classes.
+import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.util.StatusPrinter;
public class MyAppWithConfigFile {
public static void main(String[] args) {
- Logger logger = (Logger) LoggerFactory.getLogger(MyAppWithConfigFile.class);
+ Logger logger = LoggerFactory.getLogger(MyAppWithConfigFile.class);
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
- configurator.setContext(logger.getLoggerContext());
+ configurator.setContext(lc);
configurator.doConfigure(args[0]);
logger.info("Entering application.");
@@ -21,6 +23,6 @@
bar.doIt();
logger.info("Exiting application.");
- StatusPrinter.print(logger.getLoggerContext().getStatusManager());
+ StatusPrinter.print(lc.getStatusManager());
}
}
Modified: logback/classic/trunk/src/main/java/ch/qos/logback/BasicConfigurator.java
==============================================================================
--- logback/classic/trunk/src/main/java/ch/qos/logback/BasicConfigurator.java (original)
+++ logback/classic/trunk/src/main/java/ch/qos/logback/BasicConfigurator.java Tue Aug 8 21:16:32 2006
@@ -19,13 +19,12 @@
ca.setLayout(pl);
ca.start();
- Logger rootLogger = lc.getRootLogger();
+ Logger rootLogger = lc.getLogger(LoggerContext.ROOT_NAME);
rootLogger.addAppender(ca);
}
public static void configureDefaultContext() {
- Logger logger = (Logger) LoggerFactory.getLogger(BasicConfigurator.class);
- LoggerContext lc = logger.getLoggerContext();
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
configure(lc);
}
}
Modified: logback/classic/trunk/src/main/java/ch/qos/logback/classic/LoggerContext.java
==============================================================================
--- logback/classic/trunk/src/main/java/ch/qos/logback/classic/LoggerContext.java (original)
+++ logback/classic/trunk/src/main/java/ch/qos/logback/classic/LoggerContext.java Tue Aug 8 21:16:32 2006
@@ -1,11 +1,11 @@
/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
- *
- * Copyright (C) 1999-2005, QOS.ch, LOGBack.com
- *
- * 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.
+ * Logback: the reliable, generic, 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 ch.qos.logback.classic;
@@ -13,6 +13,8 @@
import java.util.HashMap;
import java.util.Hashtable;
+import org.slf4j.ILoggerFactory;
+
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.CoreGlobal;
import ch.qos.logback.core.status.ErrorStatus;
@@ -21,9 +23,11 @@
/**
* @author ceki
*/
-public class LoggerContext extends ContextBase {
+public class LoggerContext extends ContextBase implements ILoggerFactory {
- private Logger root;
+ public static final String ROOT_NAME = "root";
+
+ final Logger root;
private int size;
private int noAppenderWarning = 0;
@@ -42,22 +46,19 @@
putObject(CoreGlobal.EVALUATOR_MAP, new HashMap());
}
- /**
- * Return this contexts root logger
- *
- * @return
- */
- public Logger getRootLogger() {
- return root;
- }
-
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 (ROOT_NAME.equalsIgnoreCase(name)) {
+ return root;
+ }
+
int i = 0;
Logger logger = root;
+
Logger childLogger = (Logger) loggerCache.get(name);
// if we have the child, then let us return it without wasting time
if (childLogger != null) {
Modified: logback/classic/trunk/src/main/java/ch/qos/logback/classic/joran/action/RootLoggerAction.java
==============================================================================
--- logback/classic/trunk/src/main/java/ch/qos/logback/classic/joran/action/RootLoggerAction.java (original)
+++ logback/classic/trunk/src/main/java/ch/qos/logback/classic/joran/action/RootLoggerAction.java Tue Aug 8 21:16:32 2006
@@ -17,7 +17,6 @@
import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.spi.ExecutionContext;
-
public class RootLoggerAction extends Action {
static final String NAME_ATTR = "name";
static final String CLASS_ATTR = "class";
@@ -33,7 +32,7 @@
//logger.debug("In begin method");
LoggerContext loggerContext = (LoggerContext) this.context;
- root = loggerContext.getRootLogger();
+ root = loggerContext.getLogger(LoggerContext.ROOT_NAME);
//getLogger().debug("Pushing root logger on stack");
ec.pushObject(root);
Modified: logback/classic/trunk/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
==============================================================================
--- logback/classic/trunk/src/main/java/org/slf4j/impl/StaticLoggerBinder.java (original)
+++ logback/classic/trunk/src/main/java/org/slf4j/impl/StaticLoggerBinder.java Tue Aug 8 21:16:32 2006
@@ -1,9 +1,11 @@
package org.slf4j.impl;
-import org.slf4j.LoggerFactory;
import org.slf4j.ILoggerFactory;
+import org.slf4j.LoggerFactory;
import org.slf4j.spi.LoggerFactoryBinder;
+import ch.qos.logback.classic.LoggerContext;
+
/**
*
* The binding of {@link LoggerFactory} class with an actual instance of
@@ -17,7 +19,7 @@
* The unique instance of this class.
*/
public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
- private static final String loggerFactoryClassStr = LBLoggerFactory.class.getName();
+ private static final String loggerFactoryClassStr = LoggerContext.class.getName();
/** The ILoggerFactory instance returned by the {@link #getLoggerFactory} method
* should always be the same object
@@ -25,7 +27,9 @@
private final ILoggerFactory loggerFactory;
private StaticLoggerBinder() {
- loggerFactory = new LBLoggerFactory();
+ LoggerContext lc = new LoggerContext();
+ lc.setName("default");
+ loggerFactory = lc;
}
public ILoggerFactory getLoggerFactory() {
Modified: logback/classic/trunk/src/test/java/ch/qos/logback/classic/BasicLoggerTest.java
==============================================================================
--- logback/classic/trunk/src/test/java/ch/qos/logback/classic/BasicLoggerTest.java (original)
+++ logback/classic/trunk/src/test/java/ch/qos/logback/classic/BasicLoggerTest.java Tue Aug 8 21:16:32 2006
@@ -1,5 +1,5 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the reliable, generic, fast and flexible logging framework.
*
* Copyright (C) 1999-2006, QOS.ch
*
@@ -11,8 +11,9 @@
import junit.framework.TestCase;
-import ch.qos.logback.classic.Logger;
-import ch.qos.logback.classic.LoggerContext;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.BasicConfigurator;
import ch.qos.logback.core.appender.ListAppender;
import ch.qos.logback.core.util.StatusPrinter;
@@ -23,7 +24,7 @@
LoggerContext lc = new LoggerContext();
ListAppender listAppender = new ListAppender();
listAppender.start();
- Logger root = lc.getRootLogger();
+ Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
root.addAppender(listAppender);
Logger logger = lc.getLogger(BasicLoggerTest.class);
assertEquals(0, listAppender.list.size());
@@ -36,7 +37,7 @@
ListAppender listAppender = new ListAppender();
//listAppender.start();
listAppender.setContext(lc);
- Logger root = lc.getRootLogger();
+ Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
root.addAppender(listAppender);
Logger logger = lc.getLogger(BasicLoggerTest.class);
logger.debug("hello");
@@ -44,11 +45,10 @@
}
public void testAdditive() {
- {
LoggerContext lc = new LoggerContext();
ListAppender listAppender = new ListAppender();
listAppender.start();
- Logger root = lc.getRootLogger();
+ Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
root.addAppender(listAppender);
Logger logger = lc.getLogger(BasicLoggerTest.class);
logger.addAppender(listAppender);
@@ -56,6 +56,14 @@
logger.debug("hello");
// 1 instead of two, since logger is not additive
assertEquals(1, listAppender.list.size());
- }
+ }
+
+ public void testRootLogger() {
+ Logger logger = (Logger)LoggerFactory.getLogger(LoggerContext.ROOT_NAME);
+ LoggerContext lc = logger.getLoggerContext();
+
+ assertNotNull("Returned logger is null", logger);
+ assertEquals("Return logger isn't named root", logger.getName(), LoggerContext.ROOT_NAME);
+ assertTrue("logger instances should be indentical", logger == lc.root);
}
}
Modified: logback/classic/trunk/src/test/java/ch/qos/logback/classic/LoggerContextTest.java
==============================================================================
--- logback/classic/trunk/src/test/java/ch/qos/logback/classic/LoggerContextTest.java (original)
+++ logback/classic/trunk/src/test/java/ch/qos/logback/classic/LoggerContextTest.java Tue Aug 8 21:16:32 2006
@@ -23,7 +23,7 @@
}
public void testRootGetLogger() {
- Logger root = lc.getRootLogger();
+ Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
assertEquals(Level.DEBUG, root.getLevel());
assertEquals(Level.DEBUG, root.getEffectiveLevel());
}
Modified: logback/classic/trunk/src/test/java/ch/qos/logback/classic/joran/BasicJoranTest.java
==============================================================================
--- logback/classic/trunk/src/test/java/ch/qos/logback/classic/joran/BasicJoranTest.java (original)
+++ logback/classic/trunk/src/test/java/ch/qos/logback/classic/joran/BasicJoranTest.java Tue Aug 8 21:16:32 2006
@@ -34,7 +34,7 @@
StatusPrinter.print(loggerContext.getStatusManager());
Logger logger = loggerContext.getLogger(this.getClass().getName());
- Logger root = loggerContext.getRootLogger();
+ Logger root = loggerContext.getLogger(LoggerContext.ROOT_NAME);
ListAppender listAppender = (ListAppender) root.getAppender("LIST");
assertEquals(0, listAppender.list.size());
String msg = "hello world";
@@ -53,7 +53,7 @@
StatusPrinter.print(loggerContext.getStatusManager());
Logger logger = loggerContext.getLogger(this.getClass().getName());
- Logger root = loggerContext.getRootLogger();
+ Logger root = loggerContext.getLogger(LoggerContext.ROOT_NAME);
ListAppender listAppender = (ListAppender) root.getAppender("LIST");
assertEquals(0, listAppender.list.size());
String msg = "hello world";
More information about the logback-dev
mailing list