hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhr...@apache.org
Subject svn commit: r592324 - in /lucene/hadoop/trunk: ./ bin/ src/java/org/apache/hadoop/log/ src/java/org/apache/hadoop/mapred/ src/java/org/apache/hadoop/util/ src/test/org/apache/hadoop/log/
Date Tue, 06 Nov 2007 08:08:17 GMT
Author: dhruba
Date: Tue Nov  6 00:08:16 2007
New Revision: 592324

URL: http://svn.apache.org/viewvc?rev=592324&view=rev
Log:
HADOOP-1185. Support changing the logging level of a server without
restarting the server.  (Tsz Wo (Nicholas), SZE via dhruba)


Added:
    lucene/hadoop/trunk/src/java/org/apache/hadoop/log/
    lucene/hadoop/trunk/src/java/org/apache/hadoop/log/LogLevel.java   (with props)
    lucene/hadoop/trunk/src/java/org/apache/hadoop/util/ServletUtil.java   (with props)
    lucene/hadoop/trunk/src/test/org/apache/hadoop/log/
    lucene/hadoop/trunk/src/test/org/apache/hadoop/log/TestLogLevel.java   (with props)
Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/bin/hadoop
    lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/StatusHttpServer.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?rev=592324&r1=592323&r2=592324&view=diff
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Tue Nov  6 00:08:16 2007
@@ -41,6 +41,9 @@
     HADOOP-2086. This patch adds the ability to add dependencies to a job
     (run via JobControl) after construction.  (Adrian Woodhead via ddas)
 
+    HADOOP-1185. Support changing the logging level of a server without 
+    restarting the server.  (Tsz Wo (Nicholas), SZE via dhruba)
+
   OPTIMIZATIONS
 
     HADOOP-1898.  Release the lock protecting the last time of the last stack

Modified: lucene/hadoop/trunk/bin/hadoop
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/bin/hadoop?rev=592324&r1=592323&r2=592324&view=diff
==============================================================================
--- lucene/hadoop/trunk/bin/hadoop (original)
+++ lucene/hadoop/trunk/bin/hadoop Tue Nov  6 00:08:16 2007
@@ -46,6 +46,7 @@
   echo "  version              print the version"
   echo "  jar <jar>            run a jar file"
   echo "  distcp <srcurl> <desturl> copy file or directories recursively"
+  echo "  daemonlog            get/set the log level for each daemon"
   echo " or"
   echo "  CLASSNAME            run the class named CLASSNAME"
   echo "Most commands print help when invoked w/o parameters."
@@ -190,6 +191,8 @@
   CLASS=org.apache.hadoop.util.RunJar
 elif [ "$COMMAND" = "distcp" ] ; then
   CLASS=org.apache.hadoop.util.CopyFiles
+elif [ "$COMMAND" = "daemonlog" ] ; then
+  CLASS=org.apache.hadoop.log.LogLevel
 else
   CLASS=$COMMAND
 fi

Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/log/LogLevel.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/log/LogLevel.java?rev=592324&view=auto
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/log/LogLevel.java (added)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/log/LogLevel.java Tue Nov  6 00:08:16 2007
@@ -0,0 +1,151 @@
+/**
+ * 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.
+ */
+package org.apache.hadoop.log;
+
+import java.io.*;
+import java.net.*;
+import java.util.regex.Pattern;
+
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import org.apache.commons.logging.*;
+import org.apache.commons.logging.impl.*;
+import org.apache.hadoop.util.ServletUtil;
+
+/**
+ * Change log level in runtime.
+ */
+public class LogLevel {
+  public static final String USAGES = "\nUSAGES:\n"
+    + "java " + LogLevel.class.getName()
+    + " -getlevel <host:port> <name>\n"
+    + "java " + LogLevel.class.getName()
+    + " -setlevel <host:port> <name> <level>\n";
+
+  /**
+   * A command line implementation
+   */
+  public static void main(String[] args) {
+    if (args.length == 3 && "-getlevel".equals(args[0])) {
+      process("http://" + args[1] + "/logLevel?log=" + args[2]);
+      return;
+    }
+    else if (args.length == 4 && "-setlevel".equals(args[0])) {
+      process("http://" + args[1] + "/logLevel?log=" + args[2]
+              + "&level=" + args[3]);
+      return;
+    }
+
+    System.err.println(USAGES);
+    System.exit(-1);
+  }
+
+  private static void process(String urlstring) {
+    try {
+      URL url = new URL(urlstring);
+      System.out.println("Connecting to " + url);
+      URLConnection connection = url.openConnection();
+      connection.connect();
+
+      BufferedReader in = new BufferedReader(new InputStreamReader(
+          connection.getInputStream()));
+      for(String line; (line = in.readLine()) != null; )
+        if (line.startsWith(MARKER)) {
+          System.out.println(TAG.matcher(line).replaceAll(""));
+        }
+      in.close();
+    } catch (IOException ioe) {
+      System.err.println("" + ioe);
+    }
+  }
+
+  static final String MARKER = "<!-- OUTPUT -->";
+  static final Pattern TAG = Pattern.compile("<[^>]*>");
+
+  /**
+   * A servlet implementation
+   */
+  public static class Servlet extends HttpServlet {
+    private static final long serialVersionUID = 1L;
+
+    public void doGet(HttpServletRequest request, HttpServletResponse response
+        ) throws ServletException, IOException {
+      PrintWriter out = ServletUtil.initHTML(response, "Log Level");
+      String logName = ServletUtil.getParameter(request, "log");
+      String level = ServletUtil.getParameter(request, "level");
+
+      if (logName != null) {
+        out.println("<br /><hr /><h3>Results</h3>");
+        out.println(MARKER
+            + "Submitted Log Name: <b>" + logName + "</b><br />");
+
+        Log log = LogFactory.getLog(logName);
+        out.println(MARKER
+            + "Log Class: <b>" + log.getClass().getName() +"</b><br />");
+        if (level != null) {
+          out.println(MARKER + "Submitted Level: <b>" + level + "</b><br />");
+        }
+
+        if (log instanceof Log4JLogger) {
+          process(((Log4JLogger)log).getLogger(), level, out);
+        }
+        else if (log instanceof Jdk14Logger) {
+          process(((Jdk14Logger)log).getLogger(), level, out);
+        }
+        else {
+          out.println("Sorry, " + log.getClass() + " not supported.<br />");
+        }
+      }
+
+      out.println(FORMS);
+      out.println(ServletUtil.HTML_TAIL);
+    }
+
+    static final String FORMS = "\n<br /><hr /><h3>Get / Set</h3>"
+        + "\n<form>Log: <input type='text' size='50' name='log' /> "
+        + "<input type='submit' value='Get Log Level' />"
+        + "</form>"
+        + "\n<form>Log: <input type='text' size='50' name='log' /> "
+        + "Level: <input type='text' name='level' /> "
+        + "<input type='submit' value='Set Log Level' />"
+        + "</form>";
+
+    private static void process(org.apache.log4j.Logger log, String level,
+        PrintWriter out) throws IOException {
+      if (level != null) {
+        log.setLevel(org.apache.log4j.Level.toLevel(level));
+        out.println(MARKER + "Setting Level to " + level + " ...<br />");
+      }
+      out.println(MARKER
+          + "Effective level: <b>" + log.getEffectiveLevel() + "</b><br />");
+    }
+
+    private static void process(java.util.logging.Logger log, String level,
+        PrintWriter out) throws IOException {
+      if (level != null) {
+        log.setLevel(java.util.logging.Level.parse(level));
+        out.println(MARKER + "Setting Level to " + level + " ...<br />");
+      }
+
+      java.util.logging.Level lev;
+      for(; (lev = log.getLevel()) == null; log = log.getParent());
+      out.println(MARKER + "Effective level: <b>" + lev + "</b><br />");
+    }
+  }
+}
\ No newline at end of file

Propchange: lucene/hadoop/trunk/src/java/org/apache/hadoop/log/LogLevel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/hadoop/trunk/src/java/org/apache/hadoop/log/LogLevel.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision HeadURL

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/StatusHttpServer.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/StatusHttpServer.java?rev=592324&r1=592323&r2=592324&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/StatusHttpServer.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/mapred/StatusHttpServer.java Tue Nov  6
00:08:16 2007
@@ -93,6 +93,8 @@
       webServer.addWebApplication("/", appDir + "/" + name);
     addServlet("stacks", "/stacks", StackServlet.class);
     addServlet("reducegraph", "/taskgraph", TaskGraphServlet.class);
+    addServlet("logLevel", "/logLevel",
+        org.apache.hadoop.log.LogLevel.Servlet.class);
   }
 
   /**

Added: lucene/hadoop/trunk/src/java/org/apache/hadoop/util/ServletUtil.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/util/ServletUtil.java?rev=592324&view=auto
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/util/ServletUtil.java (added)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/util/ServletUtil.java Tue Nov  6 00:08:16
2007
@@ -0,0 +1,55 @@
+/**
+ * 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.
+ */
+package org.apache.hadoop.util;
+
+import java.io.*;
+import javax.servlet.*;
+
+public class ServletUtil {
+  /**
+   * Initial HTML header
+   */
+  public static PrintWriter initHTML(ServletResponse response, String title
+      ) throws IOException {
+    response.setContentType("text/html");
+    PrintWriter out = response.getWriter();
+    out.println("<html>\n"
+        + "<link rel='stylesheet' type='text/css' href='/static/hadoop.css'>\n"
+        + "<title>" + title + "</title>\n"
+        + "<body>\n"
+        + "<h1>" + title + "</h1>\n");
+    return out;
+  }
+
+  /**
+   * Get a parameter from a ServletRequest.
+   * Return null if the parameter contains only white spaces.
+   */
+  public static String getParameter(ServletRequest request, String name) {
+    String s = request.getParameter(name);
+    if (s == null) {
+      return null;
+    }
+    s = s.trim();
+    return s.length() == 0? null: s;
+  }
+
+  public static final String HTML_TAIL = "<hr />\n"
+    + "<a href='http://lucene.apache.org/hadoop'>Hadoop</a>, 2007.\n"
+    + "</body></html>";
+}
\ No newline at end of file

Propchange: lucene/hadoop/trunk/src/java/org/apache/hadoop/util/ServletUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/hadoop/trunk/src/java/org/apache/hadoop/util/ServletUtil.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision HeadURL

Added: lucene/hadoop/trunk/src/test/org/apache/hadoop/log/TestLogLevel.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/test/org/apache/hadoop/log/TestLogLevel.java?rev=592324&view=auto
==============================================================================
--- lucene/hadoop/trunk/src/test/org/apache/hadoop/log/TestLogLevel.java (added)
+++ lucene/hadoop/trunk/src/test/org/apache/hadoop/log/TestLogLevel.java Tue Nov  6 00:08:16
2007
@@ -0,0 +1,79 @@
+/**
+* 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.
+*/
+package org.apache.hadoop.log;
+
+import java.io.*;
+import java.net.*;
+
+import org.apache.hadoop.mapred.StatusHttpServer;
+
+import junit.framework.TestCase;
+import org.apache.commons.logging.*;
+import org.apache.commons.logging.impl.*;
+import org.apache.log4j.*;
+
+public class TestLogLevel extends TestCase {
+  static final PrintStream out = System.out;
+
+  public void testDynamicLogLevel() throws Exception {
+    String logName = TestLogLevel.class.getName();
+    Log testlog = LogFactory.getLog(logName);
+
+    //only test Log4JLogger
+    if (testlog instanceof Log4JLogger) {
+      Logger log = ((Log4JLogger)testlog).getLogger();
+      log.debug("log.debug1");
+      log.info("log.info1");
+      log.error("log.error1");
+      assertTrue(!Level.ERROR.equals(log.getEffectiveLevel()));
+
+      StatusHttpServer server = new StatusHttpServer("..",
+          "localhost", 22222, true);
+      server.start();
+      int port = server.getPort();
+
+      //servlet
+      URL url = new URL("http://localhost:" + port
+          + "/logLevel?log=" + logName + "&level=" + Level.ERROR);
+      out.println("*** Connecting to " + url);
+      URLConnection connection = url.openConnection();
+      connection.connect();
+
+      BufferedReader in = new BufferedReader(new InputStreamReader(
+          connection.getInputStream()));
+      for(String line; (line = in.readLine()) != null; out.println(line));
+      in.close();
+
+      log.debug("log.debug2");
+      log.info("log.info2");
+      log.error("log.error2");
+      assertTrue(Level.ERROR.equals(log.getEffectiveLevel()));
+
+      //command line
+      String[] args = {"-setlevel", "localhost:"+port, logName,""+Level.DEBUG};
+      LogLevel.main(args);
+      log.debug("log.debug3");
+      log.info("log.info3");
+      log.error("log.error3");
+      assertTrue(Level.DEBUG.equals(log.getEffectiveLevel()));
+    }
+    else {
+      out.println(testlog.getClass() + " not tested.");
+    }
+  }
+}
\ No newline at end of file

Propchange: lucene/hadoop/trunk/src/test/org/apache/hadoop/log/TestLogLevel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/hadoop/trunk/src/test/org/apache/hadoop/log/TestLogLevel.java
------------------------------------------------------------------------------
    svn:keywords = Id Revision HeadURL



Mime
View raw message