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 2021/12/19 23:59:02 UTC
[logging-log4j2] branch release-2.x updated: Reuse StrSubstitutor.
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
The following commit(s) were added to refs/heads/release-2.x by this push:
new 2aa5c94 Reuse StrSubstitutor.
2aa5c94 is described below
commit 2aa5c94b1bc93d373a187e1fd5990350b4e43769
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 19 18:58:51 2021 -0500
Reuse StrSubstitutor.
---
.../org/apache/log4j/helpers/OptionConverter.java | 45 +---------------------
1 file changed, 2 insertions(+), 43 deletions(-)
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java b/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java
index 6a1854b..22a867b 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java
@@ -20,6 +20,7 @@ package org.apache.log4j.helpers;
import org.apache.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.lookup.StrSubstitutor;
import org.apache.logging.log4j.util.LoaderUtil;
import java.io.InterruptedIOException;
@@ -290,49 +291,7 @@ public class OptionConverter {
* @throws IllegalArgumentException if <code>val</code> is malformed.
*/
public static String substVars(String val, Properties props) throws IllegalArgumentException {
-
- StringBuilder sbuf = new StringBuilder();
-
- int i = 0;
- int j, k;
-
- while (true) {
- j = val.indexOf(DELIM_START, i);
- if (j == -1) {
- // no more variables
- if (i == 0) { // this is a simple string
- return val;
- }
- sbuf.append(val.substring(i, val.length()));
- return sbuf.toString();
- }
- sbuf.append(val.substring(i, j));
- k = val.indexOf(DELIM_STOP, j);
- if (k == -1) {
- throw new IllegalArgumentException('"' + val +
- "\" has no closing brace. Opening brace at position " + j
- + '.');
- }
- j += DELIM_START_LEN;
- String key = val.substring(j, k);
- // first try in System properties
- String replacement = getSystemProperty(key, null);
- // then try props parameter
- if (replacement == null && props != null) {
- replacement = props.getProperty(key);
- }
-
- if (replacement != null) {
- // Do variable substitution on the replacement string
- // such that we can solve "Hello ${x2}" as "Hello p1"
- // the where the properties are
- // x1=p1
- // x2=${x1}
- String recursiveReplacement = substVars(replacement, props);
- sbuf.append(recursiveReplacement);
- }
- i = k + DELIM_STOP_LEN;
- }
+ return StrSubstitutor.replace(val, props);
}
public static org.apache.logging.log4j.Level convertLevel(String level,