Author: lindner
Date: Tue Jan 20 10:55:25 2009
New Revision: 736064

URL: http://svn.apache.org/viewvc?rev=736064&view=rev
Log:
SHINDIG-870 | Patch from Vincent Siveton | Improve logging uses when running 
tests

Added:
    incubator/shindig/trunk/java/common/src/test/resources/
    incubator/shindig/trunk/java/common/src/test/resources/logging.properties
    incubator/shindig/trunk/java/gadgets/src/test/resources/logging.properties
    
incubator/shindig/trunk/java/social-api/src/test/resources/logging.properties
Modified:
    incubator/shindig/trunk/java/gadgets/pom.xml
    
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyServlet.java
    
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/RpcServlet.java
    
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthRequestTest.java
    incubator/shindig/trunk/java/pom.xml
    incubator/shindig/trunk/java/social-api/src/test/resources/log4j.properties
    
incubator/shindig/trunk/java/social-api/src/test/resources/simplelog.properties

Added: incubator/shindig/trunk/java/common/src/test/resources/logging.properties
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/resources/logging.properties?rev=736064&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/resources/logging.properties 
(added)
+++ incubator/shindig/trunk/java/common/src/test/resources/logging.properties 
Tue Jan 20 10:55:25 2009
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+handlers=java.util.logging.ConsoleHandler
+java.util.logging.ConsoleHandler.level=ALL
+java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
+.level=INFO
+
+# Shindig commons
+org.apache.shindig.common.JsonContainerConfig.level=${java.util.logging.test.level}
+org.apache.shindig.common.cache.LruCacheProvider.level=${java.util.logging.test.level}
+org.apache.shindig.common.cache.ehcache.EhCacheCacheProvider.level=${java.util.logging.test.level}
+org.apache.shindig.common.xml.XmlUtil.level=${java.util.logging.test.level}
+
+# others
+net.sf.ehcache.Cache.level=${java.util.logging.test.level}
\ No newline at end of file

Modified: incubator/shindig/trunk/java/gadgets/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/pom.xml?rev=736064&r1=736063&r2=736064&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/pom.xml (original)
+++ incubator/shindig/trunk/java/gadgets/pom.xml Tue Jan 20 10:55:25 2009
@@ -55,9 +55,7 @@
               </includes>
             </resource>
           </webResources>
-         </configuration>
-         <executions>
-        </executions>
+        </configuration>
       </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>

Modified: 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyServlet.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyServlet.java?rev=736064&r1=736063&r2=736064&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyServlet.java
 (original)
+++ 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyServlet.java
 Tue Jan 20 10:55:25 2009
@@ -55,13 +55,13 @@
   }
 
   /**
-   * Outputs an error message for the request if it fails.
-   *
-   * TODO: Eliminate this.
+   * Outputs an error message for the request if it fails and if FINE logging 
level.
    */
   private static void outputError(GadgetException e, HttpServletResponse resp)
       throws IOException {
-    LOG.log(Level.INFO, "makeRequest failed", e);
+    if (LOG.isLoggable(Level.FINE)) {
+      LOG.log(Level.FINE, "Make Request failed", e);
+    }
     resp.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
   }
 }

Modified: 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/RpcServlet.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/RpcServlet.java?rev=736064&r1=736063&r2=736064&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/RpcServlet.java
 (original)
+++ 
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/RpcServlet.java
 Tue Jan 20 10:55:25 2009
@@ -71,7 +71,13 @@
 
     } catch (IllegalArgumentException e) {
       response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
-      logger.log(Level.INFO, e.getMessage(), e);
+      if (!logger.isLoggable(Level.OFF)) {
+        if (logger.isLoggable(Level.INFO)) {
+          logger.log(Level.INFO, e.getMessage());
+        } else {
+          logger.log(Level.INFO, e.getMessage(), e);
+        }
+      }
       return;
     }
 
@@ -129,14 +135,26 @@
       return new Result(resp.toString(), true);
     } catch (UnsupportedEncodingException e) {
       response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
-      logger.log(Level.INFO, e.getMessage(), e);
+      if (!logger.isLoggable(Level.OFF)) {
+        if (logger.isLoggable(Level.INFO)) {
+          logger.log(Level.INFO, e.getMessage());
+        } else {
+          logger.log(Level.INFO, e.getMessage(), e);
+        }
+      }
       return new Result("Unsupported input character set", false);
     } catch (JSONException e) {
       response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
       return new Result("Malformed JSON request.", false);
     } catch (RpcException e) {
       response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-      logger.log(Level.INFO, e.getMessage(), e);
+      if (!logger.isLoggable(Level.OFF)) {
+        if (logger.isLoggable(Level.INFO)) {
+          logger.log(Level.INFO, e.getMessage());
+        } else {
+          logger.log(Level.INFO, e.getMessage(), e);
+        }
+      }
       return new Result(e.getMessage(), false);
     }
   }

Modified: 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthRequestTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthRequestTest.java?rev=736064&r1=736063&r2=736064&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthRequestTest.java
 (original)
+++ 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthRequestTest.java
 Tue Jan 20 10:55:25 2009
@@ -57,6 +57,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.logging.Handler;
+import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.util.logging.Logger;
 
@@ -68,6 +69,7 @@
   private OAuthFetcherConfig fetcherConfig;
   private FakeOAuthServiceProvider serviceProvider;
   private BasicOAuthStore base;
+  private Logger logger;
   protected final List<LogRecord> logRecords = Lists.newArrayList();
   private final FakeTimeSource clock = new FakeTimeSource();
 
@@ -88,7 +90,7 @@
         getOAuthStore(base),
         clock);
 
-    Logger logger = Logger.getLogger(OAuthResponseParams.class.getName());
+    logger = Logger.getLogger(OAuthResponseParams.class.getName());
     logger.addHandler(new Handler() {
       @Override
       public void close() throws SecurityException {
@@ -1371,6 +1373,9 @@
   }
 
   private void checkLogContains(String text) {
+    if ((logger.getLevel()!=null)&&(logger.getLevel().equals(Level.OFF))) {
+        return;
+    }
     String logText = getLogText();
     if (!logText.contains(text)) {
       fail("Should have logged '" + text + "', instead got " + logText);

Added: 
incubator/shindig/trunk/java/gadgets/src/test/resources/logging.properties
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/resources/logging.properties?rev=736064&view=auto
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/resources/logging.properties 
(added)
+++ incubator/shindig/trunk/java/gadgets/src/test/resources/logging.properties 
Tue Jan 20 10:55:25 2009
@@ -0,0 +1,41 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+handlers=java.util.logging.ConsoleHandler
+java.util.logging.ConsoleHandler.level=ALL
+java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
+.level=INFO
+
+# Shindig commons
+org.apache.shindig.common.cache.LruCacheProvider.level=${java.util.logging.test.level}
+
+# Shindig gadgets
+org.apache.shindig.gadgets.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.DefaultGadgetSpecFactory.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.DefaultMessageBundleFactory.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.GadgetFeatureRegistry.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.HashLockedDomainService.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.JsLibrary.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.JsFeatureLoader.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.oauth.OAuthResponseParams.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.process.Processor.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.render.HtmlRenderer.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.render.Renderer.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.render.RenderingContentRewriter.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.servlet.MakeRequestServlet.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.servlet.RpcServlet.level=${java.util.logging.test.level}
+org.apache.shindig.gadgets.servlet.ProxyHandler.level=${java.util.logging.test.level}

Modified: incubator/shindig/trunk/java/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/pom.xml?rev=736064&r1=736063&r2=736064&view=diff
==============================================================================
--- incubator/shindig/trunk/java/pom.xml (original)
+++ incubator/shindig/trunk/java/pom.xml Tue Jan 20 10:55:25 2009
@@ -44,4 +44,39 @@
     
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/shindig/trunk/java</developerConnection>
     <url>http://svn.apache.org/viewvc/incubator/shindig/trunk/java</url>
   </scm>
+
+  <properties>
+    <java.util.logging.test.level>OFF</java.util.logging.test.level>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <systemProperties>
+            <property>
+              <name>java.util.logging.config.file</name>
+              <value>target/test-classes/logging.properties</value>
+            </property>
+          </systemProperties>
+        </configuration>
+      </plugin>
+    </plugins>
+
+    <testResources>
+      <testResource>
+        <directory>src/test/resources</directory>
+        <filtering>false</filtering>
+      </testResource>
+      <testResource>
+        <directory>src/test/resources</directory>
+        <includes>
+          <include>logging.properties</include>
+        </includes>
+        <filtering>true</filtering>
+      </testResource>
+    </testResources>
+  </build>
 </project>

Modified: 
incubator/shindig/trunk/java/social-api/src/test/resources/log4j.properties
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/resources/log4j.properties?rev=736064&r1=736063&r2=736064&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/resources/log4j.properties 
(original)
+++ incubator/shindig/trunk/java/social-api/src/test/resources/log4j.properties 
Tue Jan 20 10:55:25 2009
@@ -1,8 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
 log4j.rootCategory=info
 log4j.rootLogger=info, stdout
 
-
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern= %p %m  [%d] (%F:%L) %n
-

Added: 
incubator/shindig/trunk/java/social-api/src/test/resources/logging.properties
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/resources/logging.properties?rev=736064&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/resources/logging.properties 
(added)
+++ 
incubator/shindig/trunk/java/social-api/src/test/resources/logging.properties 
Tue Jan 20 10:55:25 2009
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+handlers=java.util.logging.ConsoleHandler
+java.util.logging.ConsoleHandler.level=ALL
+java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
+.level=INFO
+
+# Shindig commons
+org.apache.shindig.common.JsonContainerConfig.level=${java.util.logging.test.level}
+org.apache.shindig.common.xml.XmlUtil.level=${java.util.logging.test.level}
\ No newline at end of file

Modified: 
incubator/shindig/trunk/java/social-api/src/test/resources/simplelog.properties
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/resources/simplelog.properties?rev=736064&r1=736063&r2=736064&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/resources/simplelog.properties 
(original)
+++ 
incubator/shindig/trunk/java/social-api/src/test/resources/simplelog.properties 
Tue Jan 20 10:55:25 2009
@@ -1,8 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
 log4j.rootCategory=info
 log4j.rootLogger=info, stdout
 
-
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern= %p %m  [%d] (%F:%L) %n
-


Reply via email to