[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.25-11-g31c7138

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Tue Oct 19 21:09:55 CEST 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".

The branch, master has been updated
       via  31c713847189d2dc19cc51ce43f727e8ed58b917 (commit)
      from  0eeea7653973434f7288b53f741d9c16bd4a300c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=31c713847189d2dc19cc51ce43f727e8ed58b917
http://github.com/ceki/logback/commit/31c713847189d2dc19cc51ce43f727e8ed58b917

commit 31c713847189d2dc19cc51ce43f727e8ed58b917
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Tue Oct 19 21:06:32 2010 +0200

    OnConsoleStatusListener now retrospectively prints status messages
    having occured in the last 300 milliseconds.

diff --git a/logback-classic/src/test/input/joran/onConsoleRetro.xml b/logback-classic/src/test/input/joran/onConsoleRetro.xml
new file mode 100644
index 0000000..dae7437
--- /dev/null
+++ b/logback-classic/src/test/input/joran/onConsoleRetro.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+
+  <appender name="LIST" class="ch.qos.logback.core.read.ListAppender"/>
+
+  <root>
+    <level value="DEBUG"/>
+    <appender-ref ref="LIST"/>
+  </root>
+         <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"/>
+</configuration>
+  
\ No newline at end of file
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore_155/Main.java b/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore_155/Main.java
new file mode 100644
index 0000000..af7e196
--- /dev/null
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore_155/Main.java
@@ -0,0 +1,26 @@
+package ch.qos.logback.classic.issue.lbcore_155;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.core.util.StatusPrinter;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Ceki G&uuml;c&uuml;
+ */
+public class Main {
+
+  public static void main(String[] args) throws InterruptedException {
+
+    Logger logger = (Logger) LoggerFactory.getLogger(Main.class);
+    StatusPrinter.print((LoggerContext) LoggerFactory.getILoggerFactory());
+    OThread ot = new OThread();
+    ot.start();
+    Thread.sleep(OThread.WAIT_MILLIS-500);
+    logger.info("About to interrupt");
+    ot.interrupt();
+    logger.info("After interrupt");
+    logger.info("Leaving main");
+
+  }
+}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore_155/OThread.java b/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore_155/OThread.java
new file mode 100644
index 0000000..a210401
--- /dev/null
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore_155/OThread.java
@@ -0,0 +1,43 @@
+package ch.qos.logback.classic.issue.lbcore_155;
+
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.core.util.StatusPrinter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Ceki G&uuml;c&uuml;
+ */
+public class OThread extends Thread {
+
+
+  static int NANOS_IN_MILLI = 1000 * 1000;
+
+  static int WAIT_MILLIS = 10;
+
+  Logger logger = LoggerFactory.getLogger(this.getClass());
+
+  public void run() {
+
+    while (!isInterrupted()) {
+      long start = System.nanoTime();
+      for (long now = System.nanoTime(); now < start + 2*WAIT_MILLIS*NANOS_IN_MILLI; now = System.nanoTime()) {
+        logger.info("in time loop");
+      }
+
+      logger.info("before 2nd sleep");
+     
+      try {
+        sleep(1000);
+      } catch (InterruptedException e) {
+        logger.info("While sleeping", e);
+        e.printStackTrace();
+        break;
+      }
+      logger.info("after sleep");
+    }
+    logger.info("exiting WHILE");
+
+  }
+}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java
index 5cebca1..26e7555 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java
@@ -21,6 +21,7 @@ import java.util.logging.LogManager;
 
 import ch.qos.logback.classic.jul.JULHelper;
 import ch.qos.logback.core.util.StatusPrinter;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.MDC;
 
@@ -371,5 +372,17 @@ public class JoranConfiguratorTest {
     verifyJULLevel(Logger.ROOT_LOGGER_NAME, Level.TRACE);
   }
 
+  @Test
+  @Ignore
+  public void onConsoleRetro() throws JoranException, IOException, InterruptedException {
+    String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX
+            + "/onConsoleRetro.xml";
+    configure(configFileAsStr);
+    System.out.println("xxxxxxxxxxxxx");
+    Thread.sleep(400);
+
+    loggerContext.reset();
+    configure(configFileAsStr);
+  }
 
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/action/StatusListenerAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/action/StatusListenerAction.java
index 7e06e34..604ed97 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/action/StatusListenerAction.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/action/StatusListenerAction.java
@@ -13,6 +13,7 @@
  */
 package ch.qos.logback.core.joran.action;
 
+import ch.qos.logback.core.spi.ContextAware;
 import org.xml.sax.Attributes;
 
 import ch.qos.logback.core.joran.spi.ActionException;
@@ -24,35 +25,39 @@ import ch.qos.logback.core.util.OptionHelper;
 
 public class StatusListenerAction extends Action {
 
- 
+
   boolean inError = false;
   StatusListener statusListener = null;
-  
+
   public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException {
     inError = false;
     String className = attributes.getValue(CLASS_ATTRIBUTE);
-    if(OptionHelper.isEmpty(className)) {
+    if (OptionHelper.isEmpty(className)) {
       addError(
-        "Missing class name for statusListener. Near ["
-          + name + "] line " + getLineNumber(ec));
+              "Missing class name for statusListener. Near ["
+                      + name + "] line " + getLineNumber(ec));
       inError = true;
       return;
     }
-    
+
     try {
       statusListener = (StatusListener) OptionHelper.instantiateByClassName(
-          className, StatusListener.class, context);
+              className, StatusListener.class, context);
+      addInfo("Adding status listener of type ["+className+"]");
       ec.getContext().getStatusManager().add(statusListener);
+      if (statusListener instanceof ContextAware) {
+        ((ContextAware) statusListener).setContext(context);
+      }
       ec.pushObject(statusListener);
     } catch (Exception e) {
       inError = true;
       addError(
-        "Could not create an StatusListener of type ["+className+"].", e);
+              "Could not create an StatusListener of type [" + className + "].", e);
       throw new ActionException(e);
     }
-    
+
   }
- 
+
   public void finish(InterpretationContext ec) {
   }
 
@@ -66,7 +71,7 @@ public class StatusListenerAction extends Action {
     Object o = ec.peekObject();
     if (o != statusListener) {
       addWarn(
-        "The object at the of the stack is not the statusListener pushed earlier.");
+              "The object at the of the stack is not the statusListener pushed earlier.");
     } else {
       ec.popObject();
     }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/status/OnConsoleStatusListener.java b/logback-core/src/main/java/ch/qos/logback/core/status/OnConsoleStatusListener.java
index 9c1bbbd..332dcad 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/status/OnConsoleStatusListener.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/status/OnConsoleStatusListener.java
@@ -13,8 +13,6 @@
  */
 package ch.qos.logback.core.status;
 
-import ch.qos.logback.core.Context;
-import ch.qos.logback.core.spi.ContextAware;
 import ch.qos.logback.core.spi.ContextAwareBase;
 import ch.qos.logback.core.spi.LifeCycle;
 import ch.qos.logback.core.util.StatusPrinter;
@@ -29,31 +27,56 @@ import java.util.List;
 public class OnConsoleStatusListener extends ContextAwareBase implements StatusListener, LifeCycle {
 
 
-    boolean isStarted = false;
+  boolean isStarted = false;
+  long retrospective = 300;
 
-    private void print(Status status) {
-        StringBuilder sb = new StringBuilder();
-        StatusPrinter.buildStr(sb, "", status);
-        System.out.print(sb);
-    }
-    public void addStatusEvent(Status status) {
-        if (!isStarted)
-            return;
+  private void print(Status status) {
+    StringBuilder sb = new StringBuilder();
+    StatusPrinter.buildStr(sb, "", status);
+    System.out.print(sb);
+  }
+
+  public void addStatusEvent(Status status) {
+    if (!isStarted)
+      return;
+    print(status);
+  }
+
+  /**
+   * Print status messages retrospectively
+   */
+  private void retrospectivePrint() {
+    long now = System.currentTimeMillis();
+    StatusManager sm = context.getStatusManager();
+    List<Status> statusList = sm.getCopyOfStatusList();
+    for (Status status : statusList) {
+      long timestamp = status.getDate();
+      if (now - timestamp < retrospective) {
         print(status);
       }
-
-    public void start() {
-        isStarted = true;
-        StatusManager sm = context.getStatusManager();
-        List<Status>statusList = sm.getCopyOfStatusList();
-        for(sta)
     }
+  }
 
-    public void stop() {
-        isStarted = false;
+  public void start() {
+    isStarted = true;
+    if (retrospective > 0) {
+      retrospectivePrint();
     }
+  }
 
-    public boolean isStarted() {
-        return isStarted;
-    }
+  public void setRetrospective(long retrospective) {
+    this.retrospective = retrospective;
+  }
+
+  public long getRetrospective() {
+    return retrospective;
+  }
+
+  public void stop() {
+    isStarted = false;
+  }
+
+  public boolean isStarted() {
+    return isStarted;
+  }
 }

-----------------------------------------------------------------------

Summary of changes:
 .../src/test/input/joran/onConsoleRetro.xml        |   14 ++++
 .../qos/logback/classic/issue/lbcore_155/Main.java |   26 ++++++++
 .../logback/classic/issue/lbcore_155/OThread.java  |   43 +++++++++++++
 .../classic/joran/JoranConfiguratorTest.java       |   13 ++++
 .../core/joran/action/StatusListenerAction.java    |   27 +++++---
 .../core/status/OnConsoleStatusListener.java       |   67 +++++++++++++-------
 6 files changed, 157 insertions(+), 33 deletions(-)
 create mode 100644 logback-classic/src/test/input/joran/onConsoleRetro.xml
 create mode 100644 logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore_155/Main.java
 create mode 100644 logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore_155/OThread.java


hooks/post-receive
-- 
Logback: the generic, reliable, fast and flexible logging framework.


More information about the logback-dev mailing list