logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1221514 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender: flume/ rewrite/ rolling/
Date Tue, 20 Dec 2011 22:57:24 GMT
Author: rgoers
Date: Tue Dec 20 22:57:23 2011
New Revision: 1221514

URL: http://svn.apache.org/viewvc?rev=1221514&view=rev
Log:
Continue fixing checkstyle and PMD errors

Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEventFactory.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicy.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java?rev=1221514&r1=1221513&r2=1221514&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java
Tue Dec 20 22:57:23 2011
@@ -37,18 +37,10 @@ import java.util.Stack;
 import java.util.zip.GZIPOutputStream;
 
 /**
- *
+ * Class that is both a Flume and Log4j Event.
  */
 public class FlumeEvent extends EventBaseImpl implements LogEvent {
 
-    private final LogEvent event;
-
-    private byte[] body;
-
-    private final String hostname;
-
-    private final Map<String, String> ctx = new HashMap<String, String>();
-
     private static final String DEFAULT_MDC_PREFIX = "mdc:";
 
     private static final String DEFAULT_EVENT_PREFIX = "";
@@ -59,8 +51,27 @@ public class FlumeEvent extends EventBas
 
     private static final String GUID = "guId";
 
+    private final LogEvent event;
+
+    private byte[] body;
+
+    private final String hostname;
+
+    private final Map<String, String> ctx = new HashMap<String, String>();
+
     private final boolean compress;
 
+    /**
+     * Construct the FlumeEvent.
+     * @param event The Log4j LogEvent.
+     * @param hostname The host name.
+     * @param includes A comma separated list of MDC elements to include.
+     * @param excludes A comma separated list of MDC elements to exclude.
+     * @param required A comma separated list of MDC elements that are required to be defined.
+     * @param mdcPrefix The value to prefix to MDC keys.
+     * @param eventPrefix The value to prefix to event keys.
+     * @param compress If true the event body should be compressed.
+     */
     public FlumeEvent(LogEvent event, String hostname, String includes, String excludes,
String required,
                       String mdcPrefix, String eventPrefix, boolean compress) {
         this.event = event;
@@ -141,6 +152,10 @@ public class FlumeEvent extends EventBas
         fields.put(GUID, UUIDUtil.getTimeBasedUUID().toString().getBytes());
     }
 
+    /**
+     * Set the body in the event.
+     * @param body The body to add to the event.
+     */
     public void setBody(byte[] body) {
         if (body == null || body.length == 0) {
             this.body = new byte[0];
@@ -185,6 +200,10 @@ public class FlumeEvent extends EventBas
         return Priority.INFO;
     }
 
+    /**
+     * Get the Frequently Qualified Class Name.
+     * @return the FQCN String.
+     */
     public String getFQCN() {
         return event.getFQCN();
     }
@@ -204,42 +223,82 @@ public class FlumeEvent extends EventBas
         return hostname;
     }
 
+    /**
+     * Return the logging Level.
+     * @return the Level.
+     */
     public Level getLevel() {
         return event.getLevel();
     }
 
+    /**
+     * Return the logger name.
+     * @return the logger name.
+     */
     public String getLoggerName() {
         return event.getLoggerName();
     }
 
+    /**
+     * Return the StackTraceElement for the caller of the logging API.
+     * @return the StackTraceElement of the caller.
+     */
     public StackTraceElement getSource() {
         return event.getSource();
     }
 
+    /**
+     * Return the Message.
+     * @return the Message.
+     */
     public Message getMessage() {
         return event.getMessage();
     }
 
+    /**
+     * Return the Marker.
+     * @return the Marker.
+     */
     public Marker getMarker() {
         return event.getMarker();
     }
 
+    /**
+     * Return the name of the Thread.
+     * @return the name of the Thread.
+     */
     public String getThreadName() {
         return event.getThreadName();
     }
 
+    /**
+     * Return the event timestamp.
+     * @return the event timestamp.
+     */
     public long getMillis() {
         return event.getMillis();
     }
 
+    /**
+     * Return the Throwable associated with the event, if any.
+     * @return the Throwable.
+     */
     public Throwable getThrown() {
         return event.getThrown();
     }
 
+    /**
+     * Return a copy of the context Map.
+     * @return a copy of the context Map.
+     */
     public Map<String, String> getContextMap() {
         return ctx;
     }
 
+    /**
+     * Return a copy of the context stack.
+     * @return a copy of the context stack.
+     */
     public Stack<String> getContextStack() {
         return event.getContextStack();
     }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEventFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEventFactory.java?rev=1221514&r1=1221513&r2=1221514&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEventFactory.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEventFactory.java
Tue Dec 20 22:57:23 2011
@@ -19,9 +19,21 @@ package org.apache.logging.log4j.core.ap
 import org.apache.logging.log4j.core.LogEvent;
 
 /**
- *
+ * Factory to create Flume events.
  */
 public interface FlumeEventFactory {
+    /**
+     * Create a Flume event.
+     * @param event The Log4j LogEvent.
+     * @param hostname The name of the host.
+     * @param includes A comma separated list of MDC elements to include.
+     * @param excludes A comma separated list of MDC elements to exclude.
+     * @param required A comma separated list of MDC elements that are required.
+     * @param mdcPrefix The value to prefix to MDC keys.
+     * @param eventPrefix The value to prefix to event keys.
+     * @param compress If true the event body should be compressed.
+     * @return A FlumeEvent.
+     */
     FlumeEvent createEvent(LogEvent event, String hostname, String includes, String excludes,
String required,
                       String mdcPrefix, String eventPrefix, boolean compress);
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicy.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicy.java?rev=1221514&r1=1221513&r2=1221514&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicy.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicy.java
Tue Dec 20 22:57:23 2011
@@ -35,9 +35,9 @@ import java.util.Map;
  * This policy modifies events by replacing or possibly adding keys and values to the MapMessage.
  */
 @Plugin(name = "MapRewritePolicy", type = "Core", elementType = "rewritePolicy", printObject
= true)
-public class MapRewritePolicy implements RewritePolicy {
+public final class MapRewritePolicy implements RewritePolicy {
 
-    protected final static Logger logger = StatusLogger.getLogger();
+    protected final static Logger LOGGER = StatusLogger.getLogger();
 
     private final Map<String, String> map;
 
@@ -86,9 +86,17 @@ public class MapRewritePolicy implements
      * keys should be updated.
      */
     public enum Mode {
-        Add, Update
+        /**
+         * Keys should be added.
+         */
+        Add,
+        /**
+         * Keys should be updated.
+         */
+        Update
     }
 
+    @Override
     public String toString() {
         StringBuilder sb = new StringBuilder();
         sb.append("mode=").append(mode);
@@ -120,30 +128,30 @@ public class MapRewritePolicy implements
         } else {
             op = Mode.valueOf(mode);
             if (op == null) {
-                logger.error("Undefined mode " + mode);
+                LOGGER.error("Undefined mode " + mode);
                 return null;
             }
         }
         if (pairs == null || pairs.length == 0) {
-            logger.error("keys and values must be specified for the MapRewritePolicy");
+            LOGGER.error("keys and values must be specified for the MapRewritePolicy");
             return null;
         }
         Map<String, String> map = new HashMap<String, String>();
         for (KeyValuePair pair : pairs) {
             String key = pair.getKey();
             if (key == null) {
-                logger.error("A null key is not valid in MapRewritePolicy");
+                LOGGER.error("A null key is not valid in MapRewritePolicy");
                 continue;
             }
             String value = pair.getValue();
             if (value == null) {
-                logger.error("A null value for key " + key + " is not allowed in MapRewritePolicy");
+                LOGGER.error("A null value for key " + key + " is not allowed in MapRewritePolicy");
                 continue;
             }
             map.put(pair.getKey(), pair.getValue());
         }
         if (map.size() == 0) {
-            logger.error("MapRewritePolicy is not configured with any valid key value pairs");
+            LOGGER.error("MapRewritePolicy is not configured with any valid key value pairs");
             return null;
         }
         return new MapRewritePolicy(map, op);

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java?rev=1221514&r1=1221513&r2=1221514&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java
Tue Dec 20 22:57:23 2011
@@ -35,8 +35,8 @@ import java.util.concurrent.ConcurrentMa
 /**
  * This Appender allows the logging event to be manipulated before it is processed by other
Appenders.
  */
-@Plugin(name="Rewrite",type="Core",elementType="appender",printObject=true)
-public class RewriteAppender extends AppenderBase {
+@Plugin(name = "Rewrite", type = "Core", elementType = "appender", printObject = true)
+public final class RewriteAppender extends AppenderBase {
     private final Configuration config;
     private ConcurrentMap<String, AppenderControl> appenders = new ConcurrentHashMap<String,
AppenderControl>();
     private final RewritePolicy rewritePolicy;
@@ -74,6 +74,10 @@ public class RewriteAppender extends App
         }
     }
 
+    /**
+     * Modify the event and pass to the subordinate Appenders.
+     * @param event The LogEvent.
+     */
     public void append(LogEvent event) {
         if (rewritePolicy != null) {
             event = rewritePolicy.rewrite(event);
@@ -83,13 +87,23 @@ public class RewriteAppender extends App
         }
     }
 
+    /**
+     * Create a RewriteAppender.
+     * @param name The name of the Appender.
+     * @param suppress If true, exceptions will be handled in the Appender.
+     * @param appenderRefs An array of Appender names to call.
+     * @param config The Configuration.
+     * @param rewritePolicy The policy to use to modify the event.
+     * @param filter A Filter to filter events.
+     * @return The created RewriteAppender.
+     */
     @PluginFactory
     public static RewriteAppender createAppender(@PluginAttr("name") String name,
                                           @PluginAttr("suppressExceptions") String suppress,
                                           @PluginElement("appender-ref") String[] appenderRefs,
                                           @PluginConfiguration Configuration config,
                                           @PluginElement("rewritePolicy") RewritePolicy rewritePolicy,
-                                          @PluginElement("filters") Filter filter) {
+                                          @PluginElement("filter") Filter filter) {
 
         boolean handleExceptions = suppress == null ? true : Boolean.valueOf(suppress);
 
@@ -104,7 +118,14 @@ public class RewriteAppender extends App
         return new RewriteAppender(name, filter, handleExceptions, appenderRefs, rewritePolicy,
config);
     }
 
+    /**
+     * Wrap the AppenderControl simply so it can be used here.
+     */
     private static class AppenderWrapper extends AppenderControl {
+        /**
+         * Constructor.
+         * @param appender The Appender to wrap.
+         */
         public AppenderWrapper(Appender appender) {
             super(appender);
         }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java?rev=1221514&r1=1221513&r2=1221514&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/DefaultRolloverStrategy.java
Tue Dec 20 22:57:23 2011
@@ -61,6 +61,9 @@ import java.util.List;
  */
 @Plugin(name = "DefaultRolloverStrategy", type = "Core", printObject = true)
 public class DefaultRolloverStrategy implements RolloverStrategy {
+
+    protected static final Logger LOGGER = StatusLogger.getLogger();
+
     private static final int MIN_WINDOW_SIZE = 1;
     private static final int DEFAULT_WINDOW_SIZE = 7;
 
@@ -74,8 +77,6 @@ public class DefaultRolloverStrategy imp
      */
     private int minIndex;
 
-    protected static final Logger logger = StatusLogger.getLogger();
-
     /**
      * Constructs a new instance.
      * @param min The minimum index.
@@ -86,6 +87,12 @@ public class DefaultRolloverStrategy imp
         maxIndex = max;
     }
 
+    /**
+     * Perform the rollover.
+     * @param manager The RollingFileManager name for current active log file.
+     * @return A RolloverDescription.
+     * @throws SecurityException if an error occurs.
+     */
     public RolloverDescription rollover(RollingFileManager manager) throws SecurityException
{
         if (maxIndex >= 0) {
             int purgeStart = minIndex;
@@ -204,7 +211,7 @@ public class DefaultRolloverStrategy imp
                     return false;
                 }
             } catch (Exception ex) {
-                logger.warn("Exception during purge in RollingFileAppender", ex);
+                LOGGER.warn("Exception during purge in RollingFileAppender", ex);
                 return false;
             }
         }
@@ -212,10 +219,17 @@ public class DefaultRolloverStrategy imp
         return true;
     }
 
+    @Override
     public String toString() {
         return "DefaultRolloverStrategy(min=" + minIndex + ", max=" + maxIndex + ")";
     }
 
+    /**
+     * Create the DefaultRolloverStrategy.
+     * @param max The maximum number of files to keep.
+     * @param min The minimum number of files to keep.
+     * @return A DefaultRolloverStrategy.
+     */
     @PluginFactory
     public static DefaultRolloverStrategy createStrategy(@PluginAttr("max") String max,
                                                          @PluginAttr("min") String min) {
@@ -224,7 +238,7 @@ public class DefaultRolloverStrategy imp
         if (min != null) {
             minIndex = Integer.parseInt(min);
             if (minIndex < 1) {
-                logger.error("Minimum window size too small. Limited to " + MIN_WINDOW_SIZE);
+                LOGGER.error("Minimum window size too small. Limited to " + MIN_WINDOW_SIZE);
                 minIndex = MIN_WINDOW_SIZE;
             }
         } else {
@@ -235,7 +249,7 @@ public class DefaultRolloverStrategy imp
             maxIndex = Integer.parseInt(max);
             if (maxIndex < minIndex) {
                 maxIndex = minIndex < DEFAULT_WINDOW_SIZE ? DEFAULT_WINDOW_SIZE : minIndex;
-                logger.error("Maximum window size must be greater than the minimum windows
size. Set to " + maxIndex);
+                LOGGER.error("Maximum window size must be greater than the minimum windows
size. Set to " + maxIndex);
             }
         } else {
             maxIndex = DEFAULT_WINDOW_SIZE;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java?rev=1221514&r1=1221513&r2=1221514&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
Tue Dec 20 22:57:23 2011
@@ -32,13 +32,8 @@ import java.util.List;
  */
 public class PatternProcessor {
 
-    private final ArrayPatternConverter[] patternConverters;
-    private final FormattingInfo[] patternFields;
-
     private static final String KEY = "FileConverter";
 
-    private RolloverFrequency frequency = null;
-
     private static final char YEAR_CHAR = 'y';
     private static final char MONTH_CHAR = 'M';
     private static final char[] WEEK_CHARS = {'w', 'W'};
@@ -48,6 +43,11 @@ public class PatternProcessor {
     private static final char SECOND_CHAR = 's';
     private static final char MILLIS_CHAR = 'S';
 
+    private final ArrayPatternConverter[] patternConverters;
+    private final FormattingInfo[] patternFields;
+
+    private RolloverFrequency frequency = null;
+
     /**
      * Constructor.
      * @param pattern The file pattern.
@@ -137,7 +137,7 @@ public class PatternProcessor {
      * @param buf string buffer to which formatted file name is appended, may not be null.
      */
     protected final void formatFileName(final Object obj, final StringBuilder buf) {
-        Object[] objects = new Object[] { new Date(System.currentTimeMillis()), obj};
+        Object[] objects = new Object[] {new Date(System.currentTimeMillis()), obj};
         formatFileName(objects, buf);
     }
 

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java?rev=1221514&r1=1221513&r2=1221514&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
Tue Dec 20 22:57:23 2011
@@ -31,17 +31,17 @@ import java.io.OutputStream;
 import java.util.concurrent.Semaphore;
 
 /**
- * The Rolling File Manager
+ * The Rolling File Manager.
  */
 public class RollingFileManager extends FileManager {
 
+    private static ManagerFactory factory = new RollingFileManagerFactory();
+
     private long size;
     private long initialTime;
     private PatternProcessor processor;
     private final Semaphore semaphore = new Semaphore(1);
 
-    private static ManagerFactory factory = new RollingFileManagerFactory();
-
     protected RollingFileManager(String fileName, String pattern, OutputStream os, boolean
append, long size,
                                  long time) {
         super(fileName, os, append, false);
@@ -212,9 +212,9 @@ public class RollingFileManager extends 
      * Factory data.
      */
     private static class FactoryData {
-        String pattern;
-        boolean append;
-        boolean bufferedIO;
+        private String pattern;
+        private boolean append;
+        private boolean bufferedIO;
 
         /**
          * Create the data for the factory.



Mime
View raw message