This is an automated email from the ASF dual-hosted git repository.
vy 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 2c5b10c LOG4J2-2964 Merge packages from several Configurations in
Composite Configuration (#440)
2c5b10c is described below
commit 2c5b10c29dac0cbc04cb5ba4e8bf71fad531c688
Author: Valery Yatsynovich <[email protected]>
AuthorDate: Wed Feb 3 19:13:35 2021 +0300
LOG4J2-2964 Merge packages from several Configurations in Composite
Configuration (#440)
---
.../config/composite/DefaultMergeStrategy.java | 26 +++++++++++++++-------
src/site/xdoc/manual/configuration.xml.vm | 9 ++++++--
2 files changed, 25 insertions(+), 10 deletions(-)
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/DefaultMergeStrategy.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/DefaultMergeStrategy.java
index d79f33e..50e2a54 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/DefaultMergeStrategy.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/DefaultMergeStrategy.java
@@ -85,16 +85,26 @@ public class DefaultMergeStrategy implements MergeStrategy {
if (sourceLevel != null) {
targetAttribute.setValue(attribute.getValue());
}
- } else {
- if
(attribute.getKey().equalsIgnoreCase("monitorInterval")) {
- final int sourceInterval =
Integer.parseInt(attribute.getValue());
- final int targetInterval =
Integer.parseInt(targetAttribute.getValue());
- if (targetInterval == 0 || sourceInterval <
targetInterval) {
- targetAttribute.setValue(attribute.getValue());
- }
- } else {
+ } else if
(attribute.getKey().equalsIgnoreCase("monitorInterval")) {
+ final int sourceInterval =
Integer.parseInt(attribute.getValue());
+ final int targetInterval =
Integer.parseInt(targetAttribute.getValue());
+ if (targetInterval == 0 || sourceInterval <
targetInterval) {
targetAttribute.setValue(attribute.getValue());
}
+ } else if
(attribute.getKey().equalsIgnoreCase("packages")) {
+ String sourcePackages = attribute.getValue();
+ String targetPackages = targetAttribute.getValue();
+ if (sourcePackages != null) {
+ if (targetPackages != null) {
+ targetAttribute.setValue(targetPackages + ","
+ sourcePackages);
+ }
+ else {
+ targetAttribute.setValue(sourcePackages);
+ }
+ }
+ }
+ else {
+ targetAttribute.setValue(attribute.getValue());
}
isFound = true;
}
diff --git a/src/site/xdoc/manual/configuration.xml.vm
b/src/site/xdoc/manual/configuration.xml.vm
index 8e13a2e..956972d 100644
--- a/src/site/xdoc/manual/configuration.xml.vm
+++ b/src/site/xdoc/manual/configuration.xml.vm
@@ -1326,8 +1326,13 @@ rootLogger.appenderRef.stdout.ref = STDOUT
merge strategy will merge the files using the following rules:
<ol>
<li>The global configuration attributes are aggregated with
those in later configurations replacing
- those in previous configurations, with the exception that
the highest status level and the lowest
- monitorInterval greater than 0 will be used.</li>
+ those in previous configurations, with the exceptions:
+ <ul>
+ <li>the highest status level will be used</li>
+ <li>the lowest monitorInterval greater than 0 will be
used</li>
+ <li>packages are joined with comma</li>
+ </ul>
+ </li>
<li>Properties from all configurations are aggregated.
Duplicate properties replace those in previous
configurations.</li>
<li>Filters are aggregated under a CompositeFilter if more
than one Filter is defined. Since Filters