You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2022/02/19 23:31:18 UTC

[logging-log4j2] branch release-2.x updated (a8a659b -> 6bd9e06)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git.


    from a8a659b  Allow for whitespace in property files.
     new 9ccf1fd  Remove useless parentheses.
     new 3d933aa  Format.
     new 02e2cfc  Allow for whitespace in configuration files.
     new 6bd9e06  Javadoc.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/log4j/builders/AbstractBuilder.java |   4 +-
 .../builders/appender/SyslogAppenderBuilder.java   |   2 +-
 .../org/apache/log4j/helpers/PatternParser.java    | 930 ++++++++++-----------
 .../java/org/apache/log4j/spi/LocationInfo.java    |   8 +-
 .../apache/logging/log4j/util/PropertiesUtil.java  |   2 +-
 5 files changed, 449 insertions(+), 497 deletions(-)

[logging-log4j2] 04/04: Javadoc.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 6bd9e068e0a2e37f20c3a926d822206bfed08d9b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 19 18:31:16 2022 -0500

    Javadoc.
---
 .../src/main/java/org/apache/log4j/spi/LocationInfo.java          | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/spi/LocationInfo.java b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/LocationInfo.java
index a3f2fd1..4b20f2d 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/spi/LocationInfo.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/LocationInfo.java
@@ -106,28 +106,28 @@ public class LocationInfo implements Serializable {
     }
 
     /**
-     * Return the fully qualified class name of the caller making the logging request.
+     * Gets the fully qualified class name of the caller making the logging request.
      */
     public String getClassName() {
         return stackTraceElement.getClassName();
     }
 
     /**
-     * Return the file name of the caller.
+     * Gets the file name of the caller.
      */
     public String getFileName() {
         return stackTraceElement.getFileName();
     }
 
     /**
-     * Returns the line number of the caller.
+     * Gets the line number of the caller.
      */
     public String getLineNumber() {
         return Integer.toString(stackTraceElement.getLineNumber());
     }
 
     /**
-     * Returns the method name of the caller.
+     * Gets the method name of the caller.
      */
     public String getMethodName() {
         return stackTraceElement.getMethodName();

[logging-log4j2] 03/04: Allow for whitespace in configuration files.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 02e2cfc75b9f372ac465d11438d2dff70c933dea
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 19 18:31:09 2022 -0500

    Allow for whitespace in configuration files.
---
 .../src/main/java/org/apache/log4j/builders/AbstractBuilder.java      | 4 ++--
 .../org/apache/log4j/builders/appender/SyslogAppenderBuilder.java     | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/AbstractBuilder.java b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/AbstractBuilder.java
index cefb2bd..b0cfdcd 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/AbstractBuilder.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/AbstractBuilder.java
@@ -137,7 +137,7 @@ public abstract class AbstractBuilder implements Builder {
         String value = properties.getProperty(prefix + toJavaKey(key));
         value = value != null ? value : properties.getProperty(prefix + toBeanKey(key), defaultValue);
         value = value != null ? substVars(value) : defaultValue;
-        return value != null ? value : defaultValue;
+        return value != null ? value.trim() : defaultValue;
     }
 
     protected String getValueAttribute(final Element element) {
@@ -146,7 +146,7 @@ public abstract class AbstractBuilder implements Builder {
 
     protected String getValueAttribute(final Element element, final String defaultValue) {
         final String attribute = element.getAttribute(VALUE_ATTR);
-        return substVars(attribute != null ? attribute : defaultValue);
+        return substVars(attribute != null ? attribute.trim() : defaultValue);
     }
 
     protected String substVars(final String value) {
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/SyslogAppenderBuilder.java b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/SyslogAppenderBuilder.java
index 7d7947c..d85287b 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/SyslogAppenderBuilder.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/SyslogAppenderBuilder.java
@@ -162,7 +162,7 @@ public class SyslogAppenderBuilder extends AbstractBuilder implements AppenderBu
             port.set(DEFAULT_PORT);
         } else if (parts.length == 2) {
             host.set(parts[0]);
-            port.set(Integer.parseInt(parts[1]));
+            port.set(Integer.parseInt(parts[1].trim()));
         } else {
             LOGGER.warn("Invalid {} setting: {}. Using default.", SYSLOG_HOST_PARAM, syslogHost);
             host.set(DEFAULT_HOST);

[logging-log4j2] 02/04: Format.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 3d933aa2b45b68663b3d85f25d3aca0a5b0ef5c3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 19 18:28:47 2022 -0500

    Format.
---
 .../org/apache/log4j/helpers/PatternParser.java    | 930 ++++++++++-----------
 1 file changed, 441 insertions(+), 489 deletions(-)

diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/PatternParser.java b/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/PatternParser.java
index 0d3ead6..865d828 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/PatternParser.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/PatternParser.java
@@ -30,541 +30,493 @@ import java.util.Arrays;
 //                 Reinhard Deschler <re...@web.de>
 
 /**
-   Most of the work of the {@link org.apache.log4j.PatternLayout} class
-   is delegated to the PatternParser class.
-
-   <p>It is this class that parses conversion patterns and creates
-   a chained list of {@link OptionConverter OptionConverters}.
-
-   @author <a href=mailto:"cakalijp@Maritz.com">James P. Cakalic</a>
-   @author Ceki G&uuml;lc&uuml;
-   @author Anders Kristensen
-
-   @since 0.8.2
-*/
+ * Most of the work of the {@link org.apache.log4j.PatternLayout} class is delegated to the PatternParser class.
+ * 
+ * <p>
+ * It is this class that parses conversion patterns and creates a chained list of {@link OptionConverter
+ * OptionConverters}.
+ * 
+ * @author <a href=mailto:"cakalijp@Maritz.com">James P. Cakalic</a>
+ * @author Ceki G&uuml;lc&uuml;
+ * @author Anders Kristensen
+ * 
+ * @since 0.8.2
+ */
 public class PatternParser {
 
-  private static final char ESCAPE_CHAR = '%';
-
-  private static final int LITERAL_STATE = 0;
-  private static final int CONVERTER_STATE = 1;
-  private static final int DOT_STATE = 3;
-  private static final int MIN_STATE = 4;
-  private static final int MAX_STATE = 5;
-
-  static final int FULL_LOCATION_CONVERTER = 1000;
-  static final int METHOD_LOCATION_CONVERTER = 1001;
-  static final int CLASS_LOCATION_CONVERTER = 1002;
-  static final int LINE_LOCATION_CONVERTER = 1003;
-  static final int FILE_LOCATION_CONVERTER = 1004;
-
-  static final int RELATIVE_TIME_CONVERTER = 2000;
-  static final int THREAD_CONVERTER = 2001;
-  static final int LEVEL_CONVERTER = 2002;
-  static final int NDC_CONVERTER = 2003;
-  static final int MESSAGE_CONVERTER = 2004;
-
-  int state;
-  protected StringBuffer currentLiteral = new StringBuffer(32);
-  protected int patternLength;
-  protected int i;
-  PatternConverter head;
-  PatternConverter tail;
-  protected FormattingInfo formattingInfo = new FormattingInfo();
-  protected String pattern;
-
-  public
-  PatternParser(String pattern) {
-    this.pattern = pattern;
-    patternLength =  pattern.length();
-    state = LITERAL_STATE;
-  }
-
-  private
-  void  addToList(PatternConverter pc) {
-    if(head == null) {
-      head = tail = pc;
-    } else {
-      tail.next = pc;
-      tail = pc;
+    private static final char ESCAPE_CHAR = '%';
+
+    private static final int LITERAL_STATE = 0;
+    private static final int CONVERTER_STATE = 1;
+    private static final int DOT_STATE = 3;
+    private static final int MIN_STATE = 4;
+    private static final int MAX_STATE = 5;
+
+    static final int FULL_LOCATION_CONVERTER = 1000;
+    static final int METHOD_LOCATION_CONVERTER = 1001;
+    static final int CLASS_LOCATION_CONVERTER = 1002;
+    static final int LINE_LOCATION_CONVERTER = 1003;
+    static final int FILE_LOCATION_CONVERTER = 1004;
+
+    static final int RELATIVE_TIME_CONVERTER = 2000;
+    static final int THREAD_CONVERTER = 2001;
+    static final int LEVEL_CONVERTER = 2002;
+    static final int NDC_CONVERTER = 2003;
+    static final int MESSAGE_CONVERTER = 2004;
+
+    int state;
+    protected StringBuffer currentLiteral = new StringBuffer(32);
+    protected int patternLength;
+    protected int i;
+    PatternConverter head;
+    PatternConverter tail;
+    protected FormattingInfo formattingInfo = new FormattingInfo();
+    protected String pattern;
+
+    public PatternParser(String pattern) {
+        this.pattern = pattern;
+        patternLength = pattern.length();
+        state = LITERAL_STATE;
     }
-  }
-
-  protected
-  String extractOption() {
-    if((i < patternLength) && (pattern.charAt(i) == '{')) {
-      int end = pattern.indexOf('}', i);
-      if (end > i) {
-	String r = pattern.substring(i + 1, end);
-	i = end+1;
-	return r;
-      }
+
+    private void addToList(PatternConverter pc) {
+        if (head == null) {
+            head = tail = pc;
+        } else {
+            tail.next = pc;
+            tail = pc;
+        }
     }
-    return null;
-  }
-
-
-  /**
-     The option is expected to be in decimal and positive. In case of
-     error, zero is returned.  */
-  protected
-  int extractPrecisionOption() {
-    String opt = extractOption();
-    int r = 0;
-    if(opt != null) {
-      try {
-	r = Integer.parseInt(opt);
-	if(r <= 0) {
-	    LogLog.error(
-	        "Precision option (" + opt + ") isn't a positive integer.");
-	    r = 0;
-	}
-      }
-      catch (NumberFormatException e) {
-	LogLog.error("Category option \""+opt+"\" not a decimal integer.", e);
-      }
+
+    protected String extractOption() {
+        if ((i < patternLength) && (pattern.charAt(i) == '{')) {
+            int end = pattern.indexOf('}', i);
+            if (end > i) {
+                String r = pattern.substring(i + 1, end);
+                i = end + 1;
+                return r;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * The option is expected to be in decimal and positive. In case of error, zero is returned.
+     */
+    protected int extractPrecisionOption() {
+        String opt = extractOption();
+        int r = 0;
+        if (opt != null) {
+            try {
+                r = Integer.parseInt(opt);
+                if (r <= 0) {
+                    LogLog.error("Precision option (" + opt + ") isn't a positive integer.");
+                    r = 0;
+                }
+            } catch (NumberFormatException e) {
+                LogLog.error("Category option \"" + opt + "\" not a decimal integer.", e);
+            }
+        }
+        return r;
     }
-    return r;
-  }
-
-  public
-  PatternConverter parse() {
-    char c;
-    i = 0;
-    while(i < patternLength) {
-      c = pattern.charAt(i++);
-      switch(state) {
-      case LITERAL_STATE:
-        // In literal state, the last char is always a literal.
-        if(i == patternLength) {
-          currentLiteral.append(c);
-          continue;
+
+    public PatternConverter parse() {
+        char c;
+        i = 0;
+        while (i < patternLength) {
+            c = pattern.charAt(i++);
+            switch (state) {
+            case LITERAL_STATE:
+                // In literal state, the last char is always a literal.
+                if (i == patternLength) {
+                    currentLiteral.append(c);
+                    continue;
+                }
+                if (c == ESCAPE_CHAR) {
+                    // peek at the next char.
+                    switch (pattern.charAt(i)) {
+                    case ESCAPE_CHAR:
+                        currentLiteral.append(c);
+                        i++; // move pointer
+                        break;
+                    case 'n':
+                        currentLiteral.append(Layout.LINE_SEP);
+                        i++; // move pointer
+                        break;
+                    default:
+                        if (currentLiteral.length() != 0) {
+                            addToList(new LiteralPatternConverter(currentLiteral.toString()));
+                            // LogLog.debug("Parsed LITERAL converter: \""
+                            // +currentLiteral+"\".");
+                        }
+                        currentLiteral.setLength(0);
+                        currentLiteral.append(c); // append %
+                        state = CONVERTER_STATE;
+                        formattingInfo.reset();
+                    }
+                } else {
+                    currentLiteral.append(c);
+                }
+                break;
+            case CONVERTER_STATE:
+                currentLiteral.append(c);
+                switch (c) {
+                case '-':
+                    formattingInfo.leftAlign = true;
+                    break;
+                case '.':
+                    state = DOT_STATE;
+                    break;
+                default:
+                    if (c >= '0' && c <= '9') {
+                        formattingInfo.min = c - '0';
+                        state = MIN_STATE;
+                    } else
+                        finalizeConverter(c);
+                } // switch
+                break;
+            case MIN_STATE:
+                currentLiteral.append(c);
+                if (c >= '0' && c <= '9')
+                    formattingInfo.min = formattingInfo.min * 10 + (c - '0');
+                else if (c == '.')
+                    state = DOT_STATE;
+                else {
+                    finalizeConverter(c);
+                }
+                break;
+            case DOT_STATE:
+                currentLiteral.append(c);
+                if (c >= '0' && c <= '9') {
+                    formattingInfo.max = c - '0';
+                    state = MAX_STATE;
+                } else {
+                    LogLog.error("Error occured in position " + i + ".\n Was expecting digit, instead got char \"" + c + "\".");
+                    state = LITERAL_STATE;
+                }
+                break;
+            case MAX_STATE:
+                currentLiteral.append(c);
+                if (c >= '0' && c <= '9')
+                    formattingInfo.max = formattingInfo.max * 10 + (c - '0');
+                else {
+                    finalizeConverter(c);
+                    state = LITERAL_STATE;
+                }
+                break;
+            } // switch
+        } // while
+        if (currentLiteral.length() != 0) {
+            addToList(new LiteralPatternConverter(currentLiteral.toString()));
+            // LogLog.debug("Parsed LITERAL converter: \""+currentLiteral+"\".");
         }
-        if(c == ESCAPE_CHAR) {
-          // peek at the next char.
-          switch(pattern.charAt(i)) {
-          case ESCAPE_CHAR:
-            currentLiteral.append(c);
-            i++; // move pointer
+        return head;
+    }
+
+    protected void finalizeConverter(char c) {
+        PatternConverter pc = null;
+        switch (c) {
+        case 'c':
+            pc = new CategoryPatternConverter(formattingInfo, extractPrecisionOption());
+            // LogLog.debug("CATEGORY converter.");
+            // formattingInfo.dump();
+            currentLiteral.setLength(0);
             break;
-          case 'n':
-            currentLiteral.append(Layout.LINE_SEP);
-            i++; // move pointer
+        case 'C':
+            pc = new ClassNamePatternConverter(formattingInfo, extractPrecisionOption());
+            // LogLog.debug("CLASS_NAME converter.");
+            // formattingInfo.dump();
+            currentLiteral.setLength(0);
             break;
-          default:
-            if(currentLiteral.length() != 0) {
-              addToList(new LiteralPatternConverter(
-                                                  currentLiteral.toString()));
-              //LogLog.debug("Parsed LITERAL converter: \""
-              //           +currentLiteral+"\".");
+        case 'd':
+            String dateFormatStr = AbsoluteTimeDateFormat.ISO8601_DATE_FORMAT;
+            DateFormat df;
+            String dOpt = extractOption();
+            if (dOpt != null)
+                dateFormatStr = dOpt;
+
+            if (dateFormatStr.equalsIgnoreCase(AbsoluteTimeDateFormat.ISO8601_DATE_FORMAT))
+                df = new ISO8601DateFormat();
+            else if (dateFormatStr.equalsIgnoreCase(AbsoluteTimeDateFormat.ABS_TIME_DATE_FORMAT))
+                df = new AbsoluteTimeDateFormat();
+            else if (dateFormatStr.equalsIgnoreCase(AbsoluteTimeDateFormat.DATE_AND_TIME_DATE_FORMAT))
+                df = new DateTimeDateFormat();
+            else {
+                try {
+                    df = new SimpleDateFormat(dateFormatStr);
+                } catch (IllegalArgumentException e) {
+                    LogLog.error("Could not instantiate SimpleDateFormat with " + dateFormatStr, e);
+                    df = (DateFormat) OptionConverter.instantiateByClassName("org.apache.log4j.helpers.ISO8601DateFormat", DateFormat.class, null);
+                }
             }
+            pc = new DatePatternConverter(formattingInfo, df);
+            // LogLog.debug("DATE converter {"+dateFormatStr+"}.");
+            // formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+        case 'F':
+            pc = new LocationPatternConverter(formattingInfo, FILE_LOCATION_CONVERTER);
+            // LogLog.debug("File name converter.");
+            // formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+        case 'l':
+            pc = new LocationPatternConverter(formattingInfo, FULL_LOCATION_CONVERTER);
+            // LogLog.debug("Location converter.");
+            // formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+        case 'L':
+            pc = new LocationPatternConverter(formattingInfo, LINE_LOCATION_CONVERTER);
+            // LogLog.debug("LINE NUMBER converter.");
+            // formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+        case 'm':
+            pc = new BasicPatternConverter(formattingInfo, MESSAGE_CONVERTER);
+            // LogLog.debug("MESSAGE converter.");
+            // formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+        case 'M':
+            pc = new LocationPatternConverter(formattingInfo, METHOD_LOCATION_CONVERTER);
+            // LogLog.debug("METHOD converter.");
+            // formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+        case 'p':
+            pc = new BasicPatternConverter(formattingInfo, LEVEL_CONVERTER);
+            // LogLog.debug("LEVEL converter.");
+            // formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+        case 'r':
+            pc = new BasicPatternConverter(formattingInfo, RELATIVE_TIME_CONVERTER);
+            // LogLog.debug("RELATIVE time converter.");
+            // formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+        case 't':
+            pc = new BasicPatternConverter(formattingInfo, THREAD_CONVERTER);
+            // LogLog.debug("THREAD converter.");
+            // formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+        /*
+         * case 'u': if(i < patternLength) { char cNext = pattern.charAt(i); if(cNext >= '0' && cNext <= '9') { pc = new
+         * UserFieldPatternConverter(formattingInfo, cNext - '0'); LogLog.debug("USER converter ["+cNext+"].");
+         * formattingInfo.dump(); currentLiteral.setLength(0); i++; } else LogLog.error("Unexpected char"
+         * +cNext+" at position "+i); } break;
+         */
+        case 'x':
+            pc = new BasicPatternConverter(formattingInfo, NDC_CONVERTER);
+            // LogLog.debug("NDC converter.");
+            currentLiteral.setLength(0);
+            break;
+        case 'X':
+            String xOpt = extractOption();
+            pc = new MDCPatternConverter(formattingInfo, xOpt);
+            currentLiteral.setLength(0);
+            break;
+        default:
+            LogLog.error("Unexpected char [" + c + "] at position " + i + " in conversion patterrn.");
+            pc = new LiteralPatternConverter(currentLiteral.toString());
             currentLiteral.setLength(0);
-            currentLiteral.append(c); // append %
-            state = CONVERTER_STATE;
-            formattingInfo.reset();
-          }
-        }
-        else {
-          currentLiteral.append(c);
         }
-        break;
-      case CONVERTER_STATE:
-	currentLiteral.append(c);
-	switch(c) {
-	case '-':
-	  formattingInfo.leftAlign = true;
-	  break;
-	case '.':
-	  state = DOT_STATE;
-	  break;
-	default:
-	  if(c >= '0' && c <= '9') {
-	    formattingInfo.min = c - '0';
-	    state = MIN_STATE;
-	  }
-	  else
-	    finalizeConverter(c);
-	} // switch
-	break;
-      case MIN_STATE:
-	currentLiteral.append(c);
-	if(c >= '0' && c <= '9')
-	  formattingInfo.min = formattingInfo.min*10 + (c - '0');
-	else if(c == '.')
-	  state = DOT_STATE;
-	else {
-	  finalizeConverter(c);
-	}
-	break;
-      case DOT_STATE:
-	currentLiteral.append(c);
-	if(c >= '0' && c <= '9') {
-	  formattingInfo.max = c - '0';
-	   state = MAX_STATE;
-	}
-	else {
-	  LogLog.error("Error occured in position "+i
-		     +".\n Was expecting digit, instead got char \""+c+"\".");
-	  state = LITERAL_STATE;
-	}
-	break;
-      case MAX_STATE:
-	currentLiteral.append(c);
-	if(c >= '0' && c <= '9')
-	  formattingInfo.max = formattingInfo.max*10 + (c - '0');
-	else {
-	  finalizeConverter(c);
-	  state = LITERAL_STATE;
-	}
-	break;
-      } // switch
-    } // while
-    if(currentLiteral.length() != 0) {
-      addToList(new LiteralPatternConverter(currentLiteral.toString()));
-      //LogLog.debug("Parsed LITERAL converter: \""+currentLiteral+"\".");
-    }
-    return head;
-  }
-
-  protected
-  void finalizeConverter(char c) {
-    PatternConverter pc = null;
-    switch(c) {
-    case 'c':
-      pc = new CategoryPatternConverter(formattingInfo,
-					extractPrecisionOption());
-      //LogLog.debug("CATEGORY converter.");
-      //formattingInfo.dump();
-      currentLiteral.setLength(0);
-      break;
-    case 'C':
-      pc = new ClassNamePatternConverter(formattingInfo,
-					 extractPrecisionOption());
-      //LogLog.debug("CLASS_NAME converter.");
-      //formattingInfo.dump();
-      currentLiteral.setLength(0);
-      break;
-    case 'd':
-      String dateFormatStr = AbsoluteTimeDateFormat.ISO8601_DATE_FORMAT;
-      DateFormat df;
-      String dOpt = extractOption();
-      if(dOpt != null)
-	dateFormatStr = dOpt;
-
-      if(dateFormatStr.equalsIgnoreCase(
-                                    AbsoluteTimeDateFormat.ISO8601_DATE_FORMAT))
-	df = new  ISO8601DateFormat();
-      else if(dateFormatStr.equalsIgnoreCase(
-                                   AbsoluteTimeDateFormat.ABS_TIME_DATE_FORMAT))
-	df = new AbsoluteTimeDateFormat();
-      else if(dateFormatStr.equalsIgnoreCase(
-                              AbsoluteTimeDateFormat.DATE_AND_TIME_DATE_FORMAT))
-	df = new DateTimeDateFormat();
-      else {
-	try {
-	  df = new SimpleDateFormat(dateFormatStr);
-	}
-	catch (IllegalArgumentException e) {
-	  LogLog.error("Could not instantiate SimpleDateFormat with " +
-		       dateFormatStr, e);
-	  df = (DateFormat) OptionConverter.instantiateByClassName(
-			           "org.apache.log4j.helpers.ISO8601DateFormat",
-				   DateFormat.class, null);
-	}
-      }
-      pc = new DatePatternConverter(formattingInfo, df);
-      //LogLog.debug("DATE converter {"+dateFormatStr+"}.");
-      //formattingInfo.dump();
-      currentLiteral.setLength(0);
-      break;
-    case 'F':
-      pc = new LocationPatternConverter(formattingInfo,
-					FILE_LOCATION_CONVERTER);
-      //LogLog.debug("File name converter.");
-      //formattingInfo.dump();
-      currentLiteral.setLength(0);
-      break;
-    case 'l':
-      pc = new LocationPatternConverter(formattingInfo,
-					FULL_LOCATION_CONVERTER);
-      //LogLog.debug("Location converter.");
-      //formattingInfo.dump();
-      currentLiteral.setLength(0);
-      break;
-    case 'L':
-      pc = new LocationPatternConverter(formattingInfo,
-					LINE_LOCATION_CONVERTER);
-      //LogLog.debug("LINE NUMBER converter.");
-      //formattingInfo.dump();
-      currentLiteral.setLength(0);
-      break;
-    case 'm':
-      pc = new BasicPatternConverter(formattingInfo, MESSAGE_CONVERTER);
-      //LogLog.debug("MESSAGE converter.");
-      //formattingInfo.dump();
-      currentLiteral.setLength(0);
-      break;
-    case 'M':
-      pc = new LocationPatternConverter(formattingInfo,
-					METHOD_LOCATION_CONVERTER);
-      //LogLog.debug("METHOD converter.");
-      //formattingInfo.dump();
-      currentLiteral.setLength(0);
-      break;
-    case 'p':
-      pc = new BasicPatternConverter(formattingInfo, LEVEL_CONVERTER);
-      //LogLog.debug("LEVEL converter.");
-      //formattingInfo.dump();
-      currentLiteral.setLength(0);
-      break;
-    case 'r':
-      pc = new BasicPatternConverter(formattingInfo,
-					 RELATIVE_TIME_CONVERTER);
-      //LogLog.debug("RELATIVE time converter.");
-      //formattingInfo.dump();
-      currentLiteral.setLength(0);
-      break;
-    case 't':
-      pc = new BasicPatternConverter(formattingInfo, THREAD_CONVERTER);
-      //LogLog.debug("THREAD converter.");
-      //formattingInfo.dump();
-      currentLiteral.setLength(0);
-      break;
-      /*case 'u':
-      if(i < patternLength) {
-	char cNext = pattern.charAt(i);
-	if(cNext >= '0' && cNext <= '9') {
-	  pc = new UserFieldPatternConverter(formattingInfo, cNext - '0');
-	  LogLog.debug("USER converter ["+cNext+"].");
-	  formattingInfo.dump();
-	  currentLiteral.setLength(0);
-	  i++;
-	}
-	else
-	  LogLog.error("Unexpected char" +cNext+" at position "+i);
-      }
-      break;*/
-    case 'x':
-      pc = new BasicPatternConverter(formattingInfo, NDC_CONVERTER);
-      //LogLog.debug("NDC converter.");
-      currentLiteral.setLength(0);
-      break;
-    case 'X':
-      String xOpt = extractOption();
-      pc = new MDCPatternConverter(formattingInfo, xOpt);
-      currentLiteral.setLength(0);
-      break;
-    default:
-      LogLog.error("Unexpected char [" +c+"] at position "+i
-		   +" in conversion patterrn.");
-      pc = new LiteralPatternConverter(currentLiteral.toString());
-      currentLiteral.setLength(0);
-    }
 
-    addConverter(pc);
-  }
-
-  protected
-  void addConverter(PatternConverter pc) {
-    currentLiteral.setLength(0);
-    // Add the pattern converter to the list.
-    addToList(pc);
-    // Next pattern is assumed to be a literal.
-    state = LITERAL_STATE;
-    // Reset formatting info
-    formattingInfo.reset();
-  }
-
-  // ---------------------------------------------------------------------
-  //                      PatternConverters
-  // ---------------------------------------------------------------------
-
-  private static class BasicPatternConverter extends PatternConverter {
-    int type;
-
-    BasicPatternConverter(FormattingInfo formattingInfo, int type) {
-      super(formattingInfo);
-      this.type = type;
+        addConverter(pc);
     }
 
-    public
-    String convert(LoggingEvent event) {
-      switch(type) {
-      case RELATIVE_TIME_CONVERTER:
-	return (Long.toString(event.timeStamp - LoggingEvent.getStartTime()));
-      case THREAD_CONVERTER:
-	return event.getThreadName();
-      case LEVEL_CONVERTER:
-	return event.getLevel().toString();
-      case NDC_CONVERTER:
-	return event.getNDC();
-      case MESSAGE_CONVERTER: {
-	return event.getRenderedMessage();
-      }
-      default: return null;
-      }
+    protected void addConverter(PatternConverter pc) {
+        currentLiteral.setLength(0);
+        // Add the pattern converter to the list.
+        addToList(pc);
+        // Next pattern is assumed to be a literal.
+        state = LITERAL_STATE;
+        // Reset formatting info
+        formattingInfo.reset();
     }
-  }
 
-  private static class LiteralPatternConverter extends PatternConverter {
-    private String literal;
+    // ---------------------------------------------------------------------
+    // PatternConverters
+    // ---------------------------------------------------------------------
 
-    LiteralPatternConverter(String value) {
-      literal = value;
-    }
+    private static class BasicPatternConverter extends PatternConverter {
+        int type;
 
-    public
-    final
-    void format(StringBuffer sbuf, LoggingEvent event) {
-      sbuf.append(literal);
-    }
+        BasicPatternConverter(FormattingInfo formattingInfo, int type) {
+            super(formattingInfo);
+            this.type = type;
+        }
 
-    public
-    String convert(LoggingEvent event) {
-      return literal;
+        public String convert(LoggingEvent event) {
+            switch (type) {
+            case RELATIVE_TIME_CONVERTER:
+                return (Long.toString(event.timeStamp - LoggingEvent.getStartTime()));
+            case THREAD_CONVERTER:
+                return event.getThreadName();
+            case LEVEL_CONVERTER:
+                return event.getLevel().toString();
+            case NDC_CONVERTER:
+                return event.getNDC();
+            case MESSAGE_CONVERTER: {
+                return event.getRenderedMessage();
+            }
+            default:
+                return null;
+            }
+        }
     }
-  }
 
-  private static class DatePatternConverter extends PatternConverter {
-    private DateFormat df;
-    private Date date;
+    private static class LiteralPatternConverter extends PatternConverter {
+        private String literal;
 
-    DatePatternConverter(FormattingInfo formattingInfo, DateFormat df) {
-      super(formattingInfo);
-      date = new Date();
-      this.df = df;
-    }
+        LiteralPatternConverter(String value) {
+            literal = value;
+        }
+
+        public final void format(StringBuffer sbuf, LoggingEvent event) {
+            sbuf.append(literal);
+        }
 
-    public
-    String convert(LoggingEvent event) {
-      date.setTime(event.timeStamp);
-      String converted = null;
-      try {
-        converted = df.format(date);
-      }
-      catch (Exception ex) {
-        LogLog.error("Error occured while converting date.", ex);
-      }
-      return converted;
+        public String convert(LoggingEvent event) {
+            return literal;
+        }
     }
-  }
 
-  private static class MDCPatternConverter extends PatternConverter {
-    private String key;
+    private static class DatePatternConverter extends PatternConverter {
+        private DateFormat df;
+        private Date date;
 
-    MDCPatternConverter(FormattingInfo formattingInfo, String key) {
-      super(formattingInfo);
-      this.key = key;
-    }
+        DatePatternConverter(FormattingInfo formattingInfo, DateFormat df) {
+            super(formattingInfo);
+            date = new Date();
+            this.df = df;
+        }
 
-    public
-    String convert(LoggingEvent event) {
-      if (key == null) {
-          StringBuffer buf = new StringBuffer("{");
-          Map properties = event.getProperties();
-          if (properties.size() > 0) {
-            Object[] keys = properties.keySet().toArray();
-            Arrays.sort(keys);
-            for (int i = 0; i < keys.length; i++) {
-                buf.append('{');
-                buf.append(keys[i]);
-                buf.append(',');
-                buf.append(properties.get(keys[i]));
-                buf.append('}');
+        public String convert(LoggingEvent event) {
+            date.setTime(event.timeStamp);
+            String converted = null;
+            try {
+                converted = df.format(date);
+            } catch (Exception ex) {
+                LogLog.error("Error occured while converting date.", ex);
             }
-          }
-          buf.append('}');
-          return buf.toString();
-      } else {
-        Object val = event.getMDC(key);
-        if(val == null) {
-	        return null;
-        } else {
-	        return val.toString();
+            return converted;
         }
-      }
     }
-  }
 
+    private static class MDCPatternConverter extends PatternConverter {
+        private String key;
 
-  private class LocationPatternConverter extends PatternConverter {
-    int type;
+        MDCPatternConverter(FormattingInfo formattingInfo, String key) {
+            super(formattingInfo);
+            this.key = key;
+        }
 
-    LocationPatternConverter(FormattingInfo formattingInfo, int type) {
-      super(formattingInfo);
-      this.type = type;
+        public String convert(LoggingEvent event) {
+            if (key == null) {
+                StringBuffer buf = new StringBuffer("{");
+                Map properties = event.getProperties();
+                if (properties.size() > 0) {
+                    Object[] keys = properties.keySet().toArray();
+                    Arrays.sort(keys);
+                    for (int i = 0; i < keys.length; i++) {
+                        buf.append('{');
+                        buf.append(keys[i]);
+                        buf.append(',');
+                        buf.append(properties.get(keys[i]));
+                        buf.append('}');
+                    }
+                }
+                buf.append('}');
+                return buf.toString();
+            } else {
+                Object val = event.getMDC(key);
+                if (val == null) {
+                    return null;
+                } else {
+                    return val.toString();
+                }
+            }
+        }
     }
 
-    public
-    String convert(LoggingEvent event) {
-      LocationInfo locationInfo = event.getLocationInformation();
-      switch(type) {
-      case FULL_LOCATION_CONVERTER:
-	return locationInfo.fullInfo;
-      case METHOD_LOCATION_CONVERTER:
-	return locationInfo.getMethodName();
-      case LINE_LOCATION_CONVERTER:
-	return locationInfo.getLineNumber();
-      case FILE_LOCATION_CONVERTER:
-	return locationInfo.getFileName();
-      default: return null;
-      }
-    }
-  }
+    private class LocationPatternConverter extends PatternConverter {
+        int type;
 
-  private static abstract class NamedPatternConverter extends PatternConverter {
-    int precision;
+        LocationPatternConverter(FormattingInfo formattingInfo, int type) {
+            super(formattingInfo);
+            this.type = type;
+        }
 
-    NamedPatternConverter(FormattingInfo formattingInfo, int precision) {
-      super(formattingInfo);
-      this.precision =  precision;
+        public String convert(LoggingEvent event) {
+            LocationInfo locationInfo = event.getLocationInformation();
+            switch (type) {
+            case FULL_LOCATION_CONVERTER:
+                return locationInfo.fullInfo;
+            case METHOD_LOCATION_CONVERTER:
+                return locationInfo.getMethodName();
+            case LINE_LOCATION_CONVERTER:
+                return locationInfo.getLineNumber();
+            case FILE_LOCATION_CONVERTER:
+                return locationInfo.getFileName();
+            default:
+                return null;
+            }
+        }
     }
 
-    abstract
-    String getFullyQualifiedName(LoggingEvent event);
-
-    public
-    String convert(LoggingEvent event) {
-      String n = getFullyQualifiedName(event);
-      if(precision <= 0)
-	return n;
-      else {
-	int len = n.length();
-
-	// We substract 1 from 'len' when assigning to 'end' to avoid out of
-	// bounds exception in return r.substring(end+1, len). This can happen if
-	// precision is 1 and the category name ends with a dot.
-	int end = len -1 ;
-	for(int i = precision; i > 0; i--) {
-	  end = n.lastIndexOf('.', end-1);
-	  if(end == -1)
-	    return n;
-	}
-	return n.substring(end+1, len);
-      }
-    }
-  }
+    private static abstract class NamedPatternConverter extends PatternConverter {
+        int precision;
 
-  private class ClassNamePatternConverter extends NamedPatternConverter {
+        NamedPatternConverter(FormattingInfo formattingInfo, int precision) {
+            super(formattingInfo);
+            this.precision = precision;
+        }
 
-    ClassNamePatternConverter(FormattingInfo formattingInfo, int precision) {
-      super(formattingInfo, precision);
+        abstract String getFullyQualifiedName(LoggingEvent event);
+
+        public String convert(LoggingEvent event) {
+            String n = getFullyQualifiedName(event);
+            if (precision <= 0)
+                return n;
+            else {
+                int len = n.length();
+
+                // We substract 1 from 'len' when assigning to 'end' to avoid out of
+                // bounds exception in return r.substring(end+1, len). This can happen if
+                // precision is 1 and the category name ends with a dot.
+                int end = len - 1;
+                for (int i = precision; i > 0; i--) {
+                    end = n.lastIndexOf('.', end - 1);
+                    if (end == -1)
+                        return n;
+                }
+                return n.substring(end + 1, len);
+            }
+        }
     }
 
-    String getFullyQualifiedName(LoggingEvent event) {
-      return event.getLocationInformation().getClassName();
-    }
-  }
+    private class ClassNamePatternConverter extends NamedPatternConverter {
 
-  private class CategoryPatternConverter extends NamedPatternConverter {
+        ClassNamePatternConverter(FormattingInfo formattingInfo, int precision) {
+            super(formattingInfo, precision);
+        }
 
-    CategoryPatternConverter(FormattingInfo formattingInfo, int precision) {
-      super(formattingInfo, precision);
+        String getFullyQualifiedName(LoggingEvent event) {
+            return event.getLocationInformation().getClassName();
+        }
     }
 
-    String getFullyQualifiedName(LoggingEvent event) {
-      return event.getLoggerName();
+    private class CategoryPatternConverter extends NamedPatternConverter {
+
+        CategoryPatternConverter(FormattingInfo formattingInfo, int precision) {
+            super(formattingInfo, precision);
+        }
+
+        String getFullyQualifiedName(LoggingEvent event) {
+            return event.getLoggerName();
+        }
     }
-  }
 }
-

[logging-log4j2] 01/04: Remove useless parentheses.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 9ccf1fdb4b809afd9ed64b8f66a3bc6e4009e2e1
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 19 18:20:37 2022 -0500

    Remove useless parentheses.
---
 .../src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
index 250333b..4275a3c 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
@@ -376,7 +376,7 @@ public final class PropertiesUtil {
      */
     public String getStringProperty(final String name, final String defaultValue) {
         final String prop = getStringProperty(name);
-        return (prop == null) ? defaultValue : prop;
+        return prop == null ? defaultValue : prop;
     }
 
     /**