[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, lbcore224, created. v_0.9.30-6-g516d7f5

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Tue Sep 27 15:58:06 CEST 2011


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, lbcore224 has been created
        at  516d7f5faca20df0de597916b7929eefa5ee053a (commit)

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

commit 516d7f5faca20df0de597916b7929eefa5ee053a
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Tue Sep 27 15:41:11 2011 +0200

    - Add test case
    
    - Given output prdoduced by LBCORE224Test.javam, the Reduce.java
      applicaiton can remove matching LOCK/UNLOCK lines making it much
      easier to interpret the output

diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore224/LBCORE224Test.java b/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore224/LBCORE224Test.java
new file mode 100644
index 0000000..0c40880
--- /dev/null
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore224/LBCORE224Test.java
@@ -0,0 +1,30 @@
+package ch.qos.logback.classic.issue.lbcore224;
+
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.util.StatusPrinter;
+import org.apache.zookeeper.test.QuorumUtil;
+import org.junit.After;
+import org.junit.Test;
+import org.slf4j.LoggerFactory;
+
+
+public class LBCORE224Test {
+
+  final QuorumUtil qU = new QuorumUtil(1);
+
+  @After
+  public void teatDown() throws Exception {
+    Context context = (Context) LoggerFactory.getILoggerFactory();
+    StatusPrinter.print(context);
+    qU.tearDown();
+  }
+
+  @Test
+  public void test() throws Exception {
+    for (int i = 0; i < 10; i++) {
+      qU.startQuorum();
+      qU.shutdownAll();
+      System.out.println(i);
+    }
+  }
+}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore224/Reduce.java b/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore224/Reduce.java
new file mode 100644
index 0000000..6699e67
--- /dev/null
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore224/Reduce.java
@@ -0,0 +1,160 @@
+package ch.qos.logback.classic.issue.lbcore224;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Reduce a file consisting of lock and unlock operations by removing matching lock/unlocks.
+ */
+public class Reduce {
+
+  static int NA = -1;
+
+  enum OperationType {LOCK, UNLOCK}
+
+  public static void main(String[] args) throws IOException {
+    File inputFile = new File(args[0]);
+    if(!inputFile.exists()) {
+      throw new IllegalArgumentException("Missing file ["+args[0]+"]");
+    }
+    List<String> lines = readFile(inputFile);
+    System.out.println("Lines count=" + lines.size());
+    List<Structure> structuredLines = structure(lines);
+    List<Structure> reduction = reduce(structuredLines);
+    if (reduction.isEmpty()) {
+      System.out.println("Reduction is EMPTY as it should be.");
+    } else {
+      System.out.println("Non-empty reduction!!! WTF?");
+      System.out.println(reduction);
+    }
+
+
+  }
+
+  private static List<String> readFile(File  inputFile) throws IOException {
+    BufferedReader reader = null;
+    List<String> lines = new ArrayList();
+    try {
+      reader = new BufferedReader(new FileReader(inputFile));
+      String line;
+      while ((line = reader.readLine()) != null) {
+        lines.add(line);
+      }
+    } finally {
+      if (reader != null)
+        try {
+          reader.close();
+        } catch (IOException e) {
+        }
+    }
+    return lines;
+  }
+
+  private static List<Structure> reduce(List<Structure> structuredLines) {
+    List<Structure> matching = new ArrayList<Structure>();
+    int lockIndex = 0;
+    while (lockIndex < structuredLines.size()) {
+      lockIndex = findNearestLock(structuredLines, lockIndex);
+      if (lockIndex == NA)
+        break;
+      else {
+        int unlockIndex = findNearestUnlockInSameThread(structuredLines, lockIndex);
+        if (unlockIndex != NA) {
+          matching.add(structuredLines.get(lockIndex));
+          matching.add(structuredLines.get(unlockIndex));
+        }
+        lockIndex++;
+      }
+    }
+    System.out.println("matching list size: " + matching.size());
+    List<Structure> reduction = new ArrayList<Structure>();
+    for (Structure s : structuredLines) {
+      if (!matching.contains(s)) {
+        reduction.add(s);
+      }
+    }
+    return reduction;
+
+  }
+
+  private static int findNearestLock(List<Structure> reduction, int index) {
+    for (int i = index; i < reduction.size(); i++) {
+      Structure s = reduction.get(i);
+      if (s.operationType == OperationType.LOCK) {
+        return i;
+      }
+    }
+    return NA;
+  }
+
+  private static int findNearestUnlockInSameThread(List<Structure> reduction, int lockIndex) {
+    int firstCandidateIndex = lockIndex+1;
+    Structure lockStructure = reduction.get(lockIndex);
+    for (int i = firstCandidateIndex; i < reduction.size(); i++) {
+      Structure s = reduction.get(i);
+      if (s.operationType == OperationType.UNLOCK && lockStructure.thread.equals(s.thread)) {
+        return i;
+      }
+    }
+    return NA;
+  }
+
+  static List<Structure> structure(List<String> lines) {
+    List<Structure> structuredLines = new ArrayList();
+    Pattern p = Pattern.compile("(\\d{2,5})\\ +(.*) (LOCK|UNLOCK)");
+
+    for (String line : lines) {
+      Matcher m = p.matcher(line);
+      if (m.matches()) {
+        String relTime = m.group(1);
+        String t = m.group(2);
+        String opStr = m.group(3);
+        Structure structure = buildStructure(relTime, t, opStr);
+        structuredLines.add(structure);
+      } else {
+        System.out.println("NON MATCHING LINE: ["+ line+"]");
+      }
+
+    }
+    return structuredLines;
+  }
+
+  private static Structure buildStructure(String relTime, String t, String opStr) {
+    long r = Long.parseLong(relTime);
+    OperationType operationType;
+    if (opStr.equals("LOCK"))
+      operationType = OperationType.LOCK;
+    else if (opStr.equals("UNLOCK")) {
+      operationType = OperationType.UNLOCK;
+    } else {
+      throw new IllegalArgumentException(opStr + " is not LOCK|UNLOCK");
+    }
+    return new Structure(r, t, operationType);
+  }
+
+
+  static class Structure {
+    long time;
+    String thread;
+    OperationType operationType;
+
+    Structure(long time, String thread, OperationType operationType) {
+      this.time = time;
+      this.thread = thread;
+      this.operationType = operationType;
+    }
+
+    @Override
+    public String toString() {
+      return "Structure{" +
+              "time=" + time +
+              ", thread='" + thread + '\'' +
+              ", operationType=" + operationType +
+              '}';
+    }
+  }
+
+}
diff --git a/logback-classic/src/test/resources/logback-test.xml b/logback-classic/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..2c54715
--- /dev/null
+++ b/logback-classic/src/test/resources/logback-test.xml
@@ -0,0 +1,17 @@
+<configuration>
+
+
+  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+    <file>lbcore224.log</file>
+    <encoder>
+      <pattern>%logger{35} - %msg%n</pattern>
+    </encoder>
+  </appender>
+
+
+
+  <root>
+    <level value="INFO" />
+    <appender-ref ref="FILE" />
+  </root>
+</configuration>
\ No newline at end of file

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


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


More information about the logback-dev mailing list