Skip to content

Commit

Permalink
PAYARA-3161 Using environment variable in logging.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Ykus committed Nov 11, 2018
1 parent 4d0e959 commit 28695ae
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
Expand Up @@ -90,11 +90,15 @@ public interface LoggingConfig {

Map<String, String> getLoggingProperties(String targetServer) throws IOException;

Map<String, String> getLoggingProperties(String targetServer, boolean usePlaceholderReplacement) throws IOException;

/* get the properties and corresponding values in the logging.properties file.
*/

Map<String, String> getLoggingProperties() throws IOException;

Map<String, String> getLoggingProperties(boolean usePlaceholderReplacement) throws IOException;

/* creates zip file for given sourceDirectory
*/

Expand Down
Expand Up @@ -263,10 +263,10 @@ private Map<String, String> getMap(Map<String, String> properties) {
}
String property = (String) props.setProperty(key, e.getValue());
if (e.getKey().contains("javax.enterprise.system.container.web")) {
setWebLoggers(e.getValue());
setWebLoggers(new PropertyPlaceholderHelper(System.getenv(), PropertyPlaceholderHelper.ENV_REGEX).replacePlaceholder(e.getValue()));
}
//build Map of entries to return
m.put(key, property);
m.put(key, new PropertyPlaceholderHelper(System.getenv(), PropertyPlaceholderHelper.ENV_REGEX).replacePlaceholder(property));
}
return m;
}
Expand All @@ -293,9 +293,20 @@ public synchronized Map<String, String> updateLoggingProperties(Map<String, Stri
*/

public synchronized Map<String, String> getLoggingProperties(String targetConfigName) throws IOException {
return getLoggingProperties(targetConfigName, true);
}

/**
* @param targetConfigName
* @param usePlaceholderReplacement - true for placeholder replacement, false returns original property value
* @return a Map of all the properties and corresponding values in the logging.properties file.
* @throws IOException
*/
@Override
public synchronized Map<String, String> getLoggingProperties(String targetConfigName, boolean usePlaceholderReplacement) throws IOException {
loadLoggingProperties(targetConfigName);
Enumeration e = props.propertyNames();
Map<String, String> m = getMap(e);
Map<String, String> m = getMap(e, usePlaceholderReplacement);
return checkForLoggingProperties(m, targetConfigName);
}

Expand All @@ -304,21 +315,36 @@ public synchronized Map<String, String> getLoggingProperties(String targetConfig
*/

public synchronized Map<String, String> getLoggingProperties() throws IOException {
return getLoggingProperties(true);
}

/**
* @param usePlaceholderReplacement - true for placeholder replacement, false returns original property value
* @return a Map of all the properties and corresponding values in the logging.properties file.
* @throws IOException
*/
@Override
public synchronized Map<String, String> getLoggingProperties(boolean usePlaceholderReplacement) throws IOException {
loadLoggingProperties();
Enumeration e = props.propertyNames();
Map<String, String> m = getMap(e);
Map<String, String> m = getMap(e, usePlaceholderReplacement);
return checkForLoggingProperties(m, "");
}

private Map<String, String> getMap(Enumeration e) {
return getMap(e, true);
}

private Map<String, String> getMap(Enumeration e, boolean usePlaceholderReplacement) {
Map<String, String> m = new HashMap<>();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
// convert the name in domain.xml to the name in logging.properties if needed
if (LoggingXMLNames.xmltoPropsMap.get(key) != null) {
key = LoggingXMLNames.xmltoPropsMap.get(key);
}
m.put(key, props.getProperty(key));
String value = usePlaceholderReplacement ? new PropertyPlaceholderHelper(System.getenv(), PropertyPlaceholderHelper.ENV_REGEX).replacePlaceholder(props.getProperty(key)) : props.getProperty(key);
m.put(key, value);
}
return m;
}
Expand Down
Expand Up @@ -124,9 +124,9 @@ public void execute(AdminCommandContext context) {
boolean isDas = targetInfo.isDas();

if (targetConfigName != null && !targetConfigName.isEmpty()) {
props = (HashMap<String, String>) loggingConfig.getLoggingProperties(targetConfigName);
props = (HashMap<String, String>) loggingConfig.getLoggingProperties(targetConfigName, false);
} else if (isDas) {
props = (HashMap<String, String>) loggingConfig.getLoggingProperties();
props = (HashMap<String, String>) loggingConfig.getLoggingProperties(false);
} else {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
String msg = localStrings.getLocalString("invalid.target.sys.props",
Expand Down

0 comments on commit 28695ae

Please sign in to comment.