Revision: 7046
Author: [email protected]
Date: Thu Nov 19 14:35:03 2009
Log: Drop Request/Response Logging Levels down to TRACE when using the  
Remote UI. A bit of a hack had to be added to achieve this; we'll have to  
think of an improved way to pass this type of information to other areas of  
the system (such as SCLs) in the near future.

Note the special handling of the case of a 404 on favicon.ico. This is  
logged at
a lower level than other 404s (for any UI), since it's such a common error.

Review by: mmendez, jat
http://code.google.com/p/google-web-toolkit/source/detail?r=7046

Modified:
  /trunk/dev/core/src/com/google/gwt/dev/DevMode.java
  /trunk/dev/core/src/com/google/gwt/dev/DevModeBase.java
  /trunk/dev/core/src/com/google/gwt/dev/shell/jetty/JettyLauncher.java

=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/DevMode.java Thu Nov 19 13:49:05  
2009
+++ /trunk/dev/core/src/com/google/gwt/dev/DevMode.java Thu Nov 19 14:35:03  
2009
@@ -349,8 +349,17 @@
        TreeLogger serverLogger = ui.getWebServerLogger(getWebServerName(),  
null);
        serverLogger.log(TreeLogger.TRACE, "Starting HTTP on port " +  
getPort(),
            null);
-      server = options.getServletContainerLauncher().start(serverLogger,
-          getPort(), options.getWarDir());
+
+      ServletContainerLauncher scl = options.getServletContainerLauncher();
+      /*
+       * TODO: This is a hack to pass the base log level to the SCL. We'll  
have
+       * to figure out a better way to do this for SCLs in general.
+       */
+      if (scl instanceof JettyLauncher) {
+        ((JettyLauncher) scl).setBaseLogLevel(getBaseLogLevelForUI());
+      }
+
+      server = scl.start(serverLogger, getPort(), options.getWarDir());
        assert (server != null);
        return server.getPort();
      } catch (BindException e) {
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/DevModeBase.java     Thu Nov 19  
13:49:05 2009
+++ /trunk/dev/core/src/com/google/gwt/dev/DevModeBase.java     Thu Nov 19  
14:35:03 2009
@@ -143,7 +143,7 @@

      private static final String CODE_SERVER_PORT_TAG = "-codeServerPort";
      private static final String DEFAULT_PORT = "9997";
-
+
      private final OptionCodeServerPort options;

      public ArgHandlerCodeServerPort(OptionCodeServerPort options) {
@@ -157,8 +157,8 @@

      @Override
      public String getPurpose() {
-      return "Specifies the TCP port for the code server (defaults to " +
-        DEFAULT_PORT + ")";
+      return "Specifies the TCP port for the code server (defaults to "
+          + DEFAULT_PORT + ")";
      }

      @Override
@@ -372,7 +372,7 @@
        return BrowserWidgetHostChecker.whitelistRegexes(whitelistStr);
      }
    }
-
+
    protected interface HostedModeBaseOptions extends JJSOptions,  
OptionLogDir,
        OptionLogLevel, OptionGenDir, OptionNoServer, OptionPort,
        OptionCodeServerPort, OptionStartupURLs, OptionRemoteUI {
@@ -576,7 +576,7 @@

    private static final AtomicLong uniqueId = new AtomicLong();

-  public static String normalizeURL(String unknownUrlText, int port,
+  public static String normalizeURL(String unknownUrlText, int port,
        String host) {
      if (unknownUrlText.indexOf(":") != -1) {
        // Assume it's a full url.
@@ -649,6 +649,7 @@
    protected final HostedModeBaseOptions options;

    protected DevModeUI ui = null;
+  protected TreeLogger.Type baseLogLevelForUI = null;

    /**
     * Cheat on the first load's refresh by assuming the module loaded by
@@ -678,6 +679,20 @@
    public final void addStartupURL(String url) {
      options.addStartupURL(url);
    }
+
+  /**
+   * Gets the base log level recommended by the UI for INFO-level  
messages. This
+   * method can only be called once {...@link #createUI()} has been called.  
Please
+   * do not depend on this method, as it is subject to change.
+   */
+  public TreeLogger.Type getBaseLogLevelForUI() {
+    if (baseLogLevelForUI == null) {
+      throw new IllegalStateException(
+          "The ui must be created before calling this method.");
+    }
+
+    return baseLogLevelForUI;
+  }

    public final int getPort() {
      return options.getPort();
@@ -703,8 +718,8 @@
          URL url = processUrl(startupURL);
          startupUrls.put(prenormalized, url);
        } catch (UnableToCompleteException e) {
-        logger.log(TreeLogger.ERROR,
-            "Unable to process startup URL " + startupURL, null);
+        logger.log(TreeLogger.ERROR, "Unable to process startup URL "
+            + startupURL, null);
        }
      }
      ui.setStartupUrls(startupUrls);
@@ -961,8 +976,8 @@
          return false;
        }
        options.setPort(resultPort);
-      getTopLogger().log(TreeLogger.TRACE, "Started web server on port "
-          + resultPort);
+      getTopLogger().log(TreeLogger.TRACE,
+          "Started web server on port " + resultPort);
      }

      return true;
@@ -979,18 +994,32 @@
      };
    }

+  /**
+   * Create the UI and set the base log level for the UI.
+   */
    private DevModeUI createUI() {
+    DevModeUI newUI = null;
+
      if (headlessMode) {
-      return new HeadlessUI(options);
+      newUI = new HeadlessUI(options);
      } else {
        if (options.useRemoteUI()) {
-        return new RemoteUI(options.getRemoteUIHost(),
+        newUI = new RemoteUI(options.getRemoteUIHost(),
              options.getRemoteUIHostPort(), options.getClientId(),
              options.getPort(), options.getCodeServerPort());
+        baseLogLevelForUI = TreeLogger.Type.TRACE;
        }
      }

-    return new SwingUI(options);
+    if (newUI == null) {
+      newUI = new SwingUI(options);
+    }
+
+    if (baseLogLevelForUI == null) {
+      baseLogLevelForUI = TreeLogger.Type.INFO;
+    }
+
+    return newUI;
    }

    /**
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/shell/jetty/JettyLauncher.java       
 
Wed Nov 18 13:50:42 2009
+++ /trunk/dev/core/src/com/google/gwt/dev/shell/jetty/JettyLauncher.java       
 
Thu Nov 19 14:35:03 2009
@@ -52,9 +52,12 @@
        RequestLog {

      private final TreeLogger logger;
-
-    public JettyRequestLogger(TreeLogger logger) {
+    private final TreeLogger.Type normalLogLevel;
+
+    public JettyRequestLogger(TreeLogger logger, TreeLogger.Type  
normalLogLevel) {
        this.logger = logger;
+      assert (normalLogLevel != null);
+      this.normalLogLevel = normalLogLevel;
      }

      /**
@@ -70,14 +73,29 @@
        TreeLogger.Type logStatus, logHeaders;
        if (status >= 500) {
          logStatus = TreeLogger.ERROR;
+        logHeaders = TreeLogger.INFO;
+      } else if (status == 404) {
+        if ("/favicon.ico".equals(request.getRequestURI())
+            && request.getQueryString() == null) {
+          /*
+           * We do not want to call the developer's attention to a 404 when
+           * requesting favicon.ico. This is a very common 404.
+           */
+          logStatus = normalLogLevel;
+          logHeaders = TreeLogger.DEBUG;
+        } else {
+          logStatus = TreeLogger.WARN;
+          logHeaders = TreeLogger.INFO;
+        }
          logHeaders = TreeLogger.INFO;
        } else if (status >= 400) {
          logStatus = TreeLogger.WARN;
          logHeaders = TreeLogger.INFO;
        } else {
-        logStatus = TreeLogger.INFO;
+        logStatus = normalLogLevel;
          logHeaders = TreeLogger.DEBUG;
        }
+
        String userString = request.getRemoteUser();
        if (userString == null) {
          userString = "";
@@ -235,7 +253,7 @@
        try {
          server.stop();
          server.setStopAtShutdown(false);
-        branch.log(TreeLogger.INFO, "Stopped successfully");
+        branch.log(TreeLogger.TRACE, "Stopped successfully");
        } catch (Exception e) {
          branch.log(TreeLogger.ERROR, "Unable to stop embedded Jetty  
server", e);
          throw new UnableToCompleteException();
@@ -405,8 +423,8 @@
      private final TreeLogger logger;

      /**
-     * In the usual case of launching {...@link com.google.gwt.dev.DevMode},
-     * this will always by the system app ClassLoader.
+     * In the usual case of launching {...@link com.google.gwt.dev.DevMode},  
this
+     * will always by the system app ClassLoader.
       */
      private final ClassLoader systemClassLoader =  
Thread.currentThread().getContextClassLoader();

@@ -457,6 +475,9 @@
          "org.eclipse.jdt.core.JDTCompilerAdapter");
      System.setProperty("build.compiler", antJavaC);
    }
+
+  private final Object privateInstanceLock = new Object();
+  private TreeLogger.Type baseLogLevel;

    @Override
    public String getIconPath() {
@@ -467,6 +488,17 @@
    public String getName() {
      return "Jetty";
    }
+
+  /*
+   * TODO: This is a hack to pass the base log level to the SCL. We'll  
have to
+   * figure out a better way to do this for SCLs in general. Please do not
+   * depend on this method, as it is subject to change.
+   */
+  public void setBaseLogLevel(TreeLogger.Type baseLogLevel) {
+    synchronized (privateInstanceLock) {
+      this.baseLogLevel = baseLogLevel;
+    }
+  }

    @Override
    public ServletContainer start(TreeLogger logger, int port, File  
appRootDir)
@@ -499,7 +531,7 @@
          appRootDir.getAbsolutePath(), "/");

      RequestLogHandler logHandler = new RequestLogHandler();
-    logHandler.setRequestLog(new JettyRequestLogger(logger));
+    logHandler.setRequestLog(new JettyRequestLogger(logger,  
getBaseLogLevel()));
      logHandler.setHandler(wac);
      server.setHandler(logHandler);
      server.start();
@@ -530,5 +562,15 @@
        throw new NullPointerException("app root direcotry cannot be null");
      }
    }
+
+  /*
+   * TODO: This is a hack to pass the base log level to the SCL. We'll  
have to
+   * figure out a better way to do this for SCLs in general.
+   */
+  private TreeLogger.Type getBaseLogLevel() {
+    synchronized (privateInstanceLock) {
+      return this.baseLogLevel;
+    }
+  }

  }

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to