Просмотр исходного кода

commit 59f754f5b06b28d21031a52d05ea85f3e393f53a
Author: Luke Lu <llu@yahoo-inc.com>
Date: Mon Oct 25 14:57:51 2010 -0700

HADOOP:6728 Move EventCounter to org.apache.hadoop.log.metrics

in preparation of org.apache.hadoop.metrics deprecation.

See for patches/reviews.


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/yahoo-merge@1079142 13f79535-47bb-0310-9956-ffa450edef68

Owen O'Malley 14 лет назад
Родитель
Сommit
c34c5167c5

+ 1 - 1
conf/log4j.properties

@@ -115,7 +115,7 @@ log4j.logger.org.jets3t.service.impl.rest.httpclient.RestS3Service=ERROR
 # Event Counter Appender
 # Sends counts of logging messages at different severity levels to Hadoop Metrics.
 #
-log4j.appender.EventCounter=org.apache.hadoop.metrics.jvm.EventCounter
+log4j.appender.EventCounter=org.apache.hadoop.log.metrics.EventCounter
 
 #
 # Job Summary Appender

+ 34 - 0
src/java/org/apache/hadoop/log/EventCounter.java

@@ -0,0 +1,34 @@
+/**
+ * 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;
+
+/**
+ * A log4J Appender that simply counts logging events in three levels:
+ * fatal, error and warn. The class name is used in log4j.properties
+ * @deprecated use {@link org.apache.hadoop.log.metrics.EventCounter} instead
+ */
+@Deprecated
+public class EventCounter extends org.apache.hadoop.log.metrics.EventCounter {
+  static {
+    // The logging system is not started yet.
+    System.err.println("WARNING: "+ EventCounter.class.getName() +
+        " is deprecated. Please use "+
+        org.apache.hadoop.log.metrics.EventCounter.class.getName() +
+        " in all the log4j.properties files.");
+  }
+}

+ 101 - 0
src/java/org/apache/hadoop/log/metrics/EventCounter.java

@@ -0,0 +1,101 @@
+/**
+ * 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.metrics;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.Level;
+import org.apache.log4j.spi.LoggingEvent;
+
+/**
+ * A log4J Appender that simply counts logging events in three levels:
+ * fatal, error and warn. The class name is used in log4j.properties
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Stable
+public class EventCounter extends AppenderSkeleton {
+
+  private static final int FATAL = 0;
+  private static final int ERROR = 1;
+  private static final int WARN = 2;
+  private static final int INFO = 3;
+
+  private static class EventCounts {
+
+    private final long[] counts = {0, 0, 0, 0};
+
+    private synchronized void incr(int i) {
+      ++counts[i];
+    }
+
+    private synchronized long get(int i) {
+      return counts[i];
+    }
+  }
+
+  private static EventCounts counts = new EventCounts();
+
+  @InterfaceAudience.Private
+  public static long getFatal() {
+    return counts.get(FATAL);
+  }
+
+  @InterfaceAudience.Private
+  public static long getError() {
+    return counts.get(ERROR);
+  }
+
+  @InterfaceAudience.Private
+  public static long getWarn() {
+    return counts.get(WARN);
+  }
+
+  @InterfaceAudience.Private
+  public static long getInfo() {
+    return counts.get(INFO);
+  }
+
+  @Override
+  public void append(LoggingEvent event) {
+    Level level = event.getLevel();
+    if (level == Level.INFO) {
+      counts.incr(INFO);
+    }
+    else if (level == Level.WARN) {
+      counts.incr(WARN);
+    }
+    else if (level == Level.ERROR) {
+      counts.incr(ERROR);
+    }
+    else if (level == Level.FATAL) {
+      counts.incr(FATAL);
+    }
+
+  }
+
+  @Override
+  public void close() {
+  }
+
+  @Override
+  public boolean requiresLayout() {
+    return false;
+  }
+}

+ 10 - 73
src/java/org/apache/hadoop/metrics/jvm/EventCounter.java

@@ -17,82 +17,19 @@
  */
 package org.apache.hadoop.metrics.jvm;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
-import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.Level;
-import org.apache.log4j.spi.LoggingEvent;
-
 /**
  * A log4J Appender that simply counts logging events in three levels:
  * fatal, error and warn.
+ * @deprecated use {@link org.apache.hadoop.log.metrics.EventCounter} instead
  */
-@InterfaceAudience.Private
-@InterfaceStability.Evolving
-public class EventCounter extends AppenderSkeleton {
-        
-    private static final int FATAL = 0;
-    private static final int ERROR = 1;
-    private static final int WARN  = 2;
-    private static final int INFO  = 3;
-    
-    private static class EventCounts {
-        private final long[] counts = { 0, 0, 0, 0 };
-    
-        private synchronized void incr(int i) { 
-            ++counts[i]; 
-        }
-        
-        private synchronized long get(int i) { 
-            return counts[i]; 
-        }
-    }
-    private static EventCounts counts = new EventCounts();
-    
-    public static long getFatal() { 
-        return counts.get(FATAL); 
-    }
-    
-    public static long getError() { 
-        return counts.get(ERROR); 
-    }
-    
-    public static long getWarn() { 
-        return counts.get(WARN);  
-    }
-    
-    public static long getInfo() {
-        return counts.get(INFO);
-    }
-    
-    public void append(LoggingEvent event) {
-        Level level = event.getLevel();
-        if (level == Level.INFO) {
-            counts.incr(INFO);
-        }
-        else if (level == Level.WARN) {
-            counts.incr(WARN);
-        }
-        else if (level == Level.ERROR) {
-            counts.incr(ERROR);
-        }
-        else if (level == Level.FATAL) {
-            counts.incr(FATAL);
-        }
+@Deprecated
+public class EventCounter extends org.apache.hadoop.log.metrics.EventCounter {
 
-    }
-    
-    // Strange: these two methods are abstract in AppenderSkeleton, but not
-    // included in the javadoc (log4j 1.2.13).
-    
-    public void close() {
-    }
-    public boolean requiresLayout() {
-        return false;
-    }
-    
-    
-    
+  static {
+    // The logging system is not started yet.
+    System.err.println("WARNING: "+ EventCounter.class.getName() +
+        " is deprecated. Please use "+
+        org.apache.hadoop.log.metrics.EventCounter.class.getName() +
+        " in all the log4j.properties files.");
+  }
 }

+ 5 - 0
src/java/org/apache/hadoop/util/VersionInfo.java

@@ -18,6 +18,8 @@
 
 package org.apache.hadoop.util;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.HadoopVersionAnnotation;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
@@ -29,6 +31,8 @@ import org.apache.hadoop.classification.InterfaceStability;
 @InterfaceAudience.Private
 @InterfaceStability.Unstable
 public class VersionInfo {
+  private static final Log LOG = LogFactory.getLog(VersionInfo.class);
+
   private static Package myPackage;
   private static HadoopVersionAnnotation version;
   
@@ -112,6 +116,7 @@ public class VersionInfo {
   }
   
   public static void main(String[] args) {
+    LOG.debug("version: "+ version);
     System.out.println("Hadoop " + getVersion());
     System.out.println("Subversion " + getUrl() + " -r " + getRevision());
     System.out.println("Compiled by " + getUser() + " on " + getDate());