Skip to content

Commit

Permalink
Merge pull request eclipse-ee4j#25289 from tnagao7/fix-delete-log-levels
Browse files Browse the repository at this point in the history
Fix eclipse-ee4j#25288 asadmin delete-log-levels command fails if the --target option is specified
  • Loading branch information
dmatej authored Dec 19, 2024
2 parents 2e10ed7 + ba83125 commit bebc07c
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -232,7 +232,7 @@ public synchronized String setLoggingProperty(String propertyName, String proper
setWebLoggers(propertyValue);
}

closePropFile("");
closePropFile(null);
return property;
}

Expand Down Expand Up @@ -298,7 +298,7 @@ public synchronized Map<String, String> updateLoggingProperties(Map<String, Stri
m.put(key, property);

}
closePropFile("");
closePropFile(null);
return m;
}

Expand Down Expand Up @@ -385,7 +385,7 @@ public synchronized Map<String, String> deleteLoggingProperties(final Collection
LOG.log(Level.INFO, "deleteLoggingProperties(properties={0})", properties);
loadLoggingProperties();
remove(properties);
rewritePropertiesFileAndNotifyMonitoring();
rewritePropertiesFileAndNotifyMonitoring(null);
return setMissingDefaults(getLoggingProperties());
}

Expand All @@ -394,21 +394,26 @@ public synchronized Map<String, String> deleteLoggingProperties(final Collection
public synchronized Map<String, String> deleteLoggingProperties(final Collection<String> properties,
final String target) throws IOException {
LOG.log(Level.INFO, "deleteLoggingProperties(properties={0}, target={1})", new Object[] {properties, target});
loadLoggingProperties();
loadLoggingProperties(target);
remove(properties);
rewritePropertiesFileAndNotifyMonitoring();
return setMissingDefaults(getLoggingProperties());
rewritePropertiesFileAndNotifyMonitoring(target);
return setMissingDefaults(getLoggingProperties(target));
}

private void remove(final Collection<String> keys) {
final Consumer<String> toRealKeyAndDelete = k -> props.remove(LoggingXMLNames.xmltoPropsMap.getOrDefault(k, k));
keys.forEach(toRealKeyAndDelete);
}

private void rewritePropertiesFileAndNotifyMonitoring() throws IOException {
private void rewritePropertiesFileAndNotifyMonitoring(final String targetConfigName) throws IOException {
LOG.finest("rewritePropertiesFileAndNotifyMonitoring");
File file = getLoggingPropertiesFile();
File parentFile = file.getParentFile();
final File file;
if (targetConfigName == null || targetConfigName.isEmpty()) {
file = getLoggingPropertiesFile();
} else {
file = getLoggingPropertiesFile(targetConfigName);
}
final File parentFile = file.getParentFile();
if (!parentFile.exists() && !parentFile.mkdirs()) {
throw new IOException(
"Directory '" + parentFile + "' does not exist, cannot create logging.properties file!");
Expand Down

0 comments on commit bebc07c

Please sign in to comment.