lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r1294967 - in /lucene/dev/trunk/solr: core/src/java/org/apache/solr/ core/src/java/org/apache/solr/core/ core/src/java/org/apache/solr/update/processor/ core/src/test/org/apache/solr/cloud/ test-framework/src/java/org/apache/solr/
Date Wed, 29 Feb 2012 04:12:36 GMT
Author: yonik
Date: Wed Feb 29 04:12:35 2012
New Revision: 1294967

URL: http://svn.apache.org/viewvc?rev=1294967&view=rev
Log:
SOLR-3157: restrict changes to logging string to formatter

Modified:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/SolrLogFormatter.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrCore.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/processor/LogUpdateProcessorFactory.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudTest.java
    lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/SolrLogFormatter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/SolrLogFormatter.java?rev=1294967&r1=1294966&r2=1294967&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/SolrLogFormatter.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/SolrLogFormatter.java Wed Feb 29 04:12:35
2012
@@ -54,17 +54,33 @@ public class SolrLogFormatter extends Fo
       return className + '.' + methodName;
     }
   }
-  
-  
 
-  
-  protected SolrLogFormatter() {
+
+  public SolrLogFormatter() {
     super();
     
     methodAlias.put(new Method("org.apache.solr.update.processor.LogUpdateProcessor","finish"),
"UPDATE");
     methodAlias.put(new Method("org.apache.solr.core.SolrCore","execute"), "REQ");
   }
 
+
+  // TODO: name this better... it's only for cloud tests where every core container has just
one solr server so Port/Core are fine
+  public boolean shorterFormat = false;
+
+  /**  Removes info that is redundant for current cloud tests including core name, webapp,
and common labels path= and params=
+   * [] webapp=/solr path=/select params={q=foobarbaz} hits=0 status=0 QTime=1
+   * /select {q=foobarbaz} hits=0 status=0 QTime=1
+   * NOTE: this is a work in progress and different settings may be ideal for other types
of tests.
+   */
+  public void setShorterFormat() {
+    shorterFormat = true;
+    // looking at /update is enough... we don't need "UPDATE /update"
+    methodAlias.put(new Method("org.apache.solr.update.processor.LogUpdateProcessor","finish"),
"");
+  }
+
+
+
+
   public static class CoreInfo {
     public static int maxCoreNum;
     public String shortId;
@@ -188,10 +204,13 @@ sb.append("(group_name=").append(tg.getN
       sb.append(' ').append(info.shortId);                     // core
     }
     if (zkController != null) {
-      sb.append(" P").append(zkController.getHostPort());
+      sb.append(" P").append(zkController.getHostPort());      // todo: should be able to
get this from core container for non zk tests
+    }
+
+    if (shortClassName.length() > 0) {
+      sb.append(' ').append(shortClassName);
     }
 
-    sb.append(' ').append(shortClassName);
     if (record.getLevel() != Level.INFO) {
       sb.append(' ').append(record.getLevel());
     }
@@ -254,20 +273,62 @@ sb.append("(group_name=").append(tg.getN
     return sb.toString() + '.' + method;
   }
   
+  private void addFirstLine(StringBuilder sb, String msg) {
+//    INFO: [] webapp=/solr path=/select params={q=foobarbaz} hits=0 status=0 QTime=1
+
+    if (!shorterFormat || !msg.startsWith("[")) {
+      sb.append(msg);      
+      return;
+    }
+
+    int idx = msg.indexOf(']');
+    if (idx < 0 || !msg.startsWith(" webapp=", idx+1)) {
+      sb.append(msg);
+      return;
+    }
+    
+    idx = msg.indexOf(' ',idx+8); // space after webapp=
+    if (idx < 0) { sb.append(msg); return; }
+    idx = msg.indexOf('=',idx+1);   // = in  path=
+    if (idx < 0) { sb.append(msg); return; }
+
+    int idx2 = msg.indexOf(' ',idx+1);
+    if (idx2 < 0) { sb.append(msg); return; }
+
+
+    sb.append(msg.substring(idx+1, idx2+1));  // path
+    
+    idx = msg.indexOf("params=", idx2);
+    if (idx < 0) {
+      sb.append(msg.substring(idx2));
+    } else {
+      sb.append(msg.substring(idx+7));
+    }
+  }
+  
   private void appendMultiLineString(StringBuilder sb, String msg) {
     int idx = msg.indexOf('\n');
     if (idx < 0) {
-      sb.append(msg);
+      addFirstLine(sb, msg);
       return;
     }
 
     int lastIdx = -1;
     for (;;) {
       if (idx < 0) {
-        sb.append(msg.substring(lastIdx+1));
+        if (lastIdx == -1) {
+          addFirstLine(sb, msg.substring(lastIdx+1));
+        } else {
+          sb.append(msg.substring(lastIdx+1));
+        }
         break;
       }
-      sb.append(msg.substring(lastIdx+1, idx));
+      if (lastIdx == -1) {
+        addFirstLine(sb, msg.substring(lastIdx+1, idx));
+      } else {
+        sb.append(msg.substring(lastIdx+1, idx));
+      }
+
       sb.append("\n\t");
       lastIdx = idx;
       idx = msg.indexOf('\n',lastIdx+1);
@@ -352,7 +413,7 @@ sb.append("(group_name=").append(tg.getN
       @Override
       public void run() {
         threadLocal.set("from thread1");
-        log.error("InThread1");
+        log.error("[] webapp=/solr path=/select params={hello} wow");
       }
     };
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrCore.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrCore.java?rev=1294967&r1=1294966&r2=1294967&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrCore.java Wed Feb 29 04:12:35
2012
@@ -1536,17 +1536,15 @@ public final class SolrCore implements S
     // for back compat, we set these now just in case other code
     // are expecting them during handleRequest
 
-    if (!isTestLoggingFormat) {
-      toLog.add("webapp", req.getContext().get("webapp"));
-    }
-    toLog.add(isTestLoggingFormat ? null : "path", req.getContext().get("path"));
-    toLog.add(isTestLoggingFormat ? null : "params", "{" + req.getParamString() + "}");
+    toLog.add("webapp", req.getContext().get("webapp"));
+    toLog.add("path", req.getContext().get("path"));
+    toLog.add("params", "{" + req.getParamString() + "}");
 
     handler.handleRequest(req,rsp);
     setResponseHeaderValues(handler,req,rsp);
 
     if (log.isInfoEnabled() && toLog.size() > 0) {
-      StringBuilder sb = new StringBuilder();
+      StringBuilder sb = new StringBuilder(logid);
       for (int i=0; i<toLog.size(); i++) {
         String name = toLog.getName(i);
         Object val = toLog.getVal(i);

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/processor/LogUpdateProcessorFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/processor/LogUpdateProcessorFactory.java?rev=1294967&r1=1294966&r2=1294967&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/processor/LogUpdateProcessorFactory.java
(original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/processor/LogUpdateProcessorFactory.java
Wed Feb 29 04:12:35 2012
@@ -181,7 +181,7 @@ class LogUpdateProcessor extends UpdateR
 
     NamedList<Object> stdLog = rsp.getToLog();
 
-    StringBuilder sb = new StringBuilder();
+    StringBuilder sb = new StringBuilder(req.getCore().getLogId());
 
     for (int i=0; i<stdLog.size(); i++) {
       String name = stdLog.getName(i);

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudTest.java?rev=1294967&r1=1294966&r2=1294967&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudTest.java Wed Feb
29 04:12:35 2012
@@ -60,7 +60,12 @@ import org.junit.Ignore;
  */
 @Ignore
 public class FullSolrCloudTest extends AbstractDistributedZkTestCase {
-  
+  @BeforeClass
+  public static void beforeFullSolrCloudTest() throws Exception {
+    // shorten the log output more for this test type
+    if (formatter != null) formatter.setShorterFormat();
+  }
+
   private static final String SHARD2 = "shard2";
   
   private boolean printLayoutOnTearDown = false;

Modified: lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java?rev=1294967&r1=1294966&r2=1294967&view=diff
==============================================================================
--- lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java (original)
+++ lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java Wed
Feb 29 04:12:35 2012
@@ -43,6 +43,7 @@ import org.apache.solr.schema.SchemaFiel
 import org.apache.solr.search.SolrIndexSearcher;
 import org.apache.solr.servlet.DirectSolrConnection;
 import org.apache.solr.util.TestHarness;
+import org.apache.zookeeper.server.LogFormatter;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.slf4j.Logger;
@@ -97,6 +98,7 @@ public abstract class SolrTestCaseJ4 ext
     super.tearDown();
   }
 
+  public static SolrLogFormatter formatter;
 
   public static void setupLogging() {
     SolrCore.isTestLoggingFormat = true;
@@ -116,7 +118,8 @@ public abstract class SolrTestCaseJ4 ext
     }
 
     consoleHandler.setLevel(Level.ALL);
-    consoleHandler.setFormatter(new SolrLogFormatter());
+    formatter = new SolrLogFormatter();
+    consoleHandler.setFormatter(formatter);
 
     if (register) {
       java.util.logging.Logger.getLogger("").addHandler(consoleHandler);



Mime
View raw message