Skip to content

Commit d445a3e

Browse files
committed
Merge remote-tracking branch 'apache/2.x' into fix/2.x/use-random-logging-path
2 parents 6291ab4 + e1715dc commit d445a3e

File tree

361 files changed

+7748
-5427
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

361 files changed

+7748
-5427
lines changed

BUILDING.adoc

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,59 @@ CI=true ./mvnw ...
172172
=== Compilation in IntelliJ IDEA fails with `java: plug-in not found: ErrorProne`
173173
174174
Try removing all _"Override compiler parameters per-module"_ entries in _"Settings > Build, Execution, Deployment > Compiler > Java Compiler"_.
175+
176+
[#development-api-compatibility]
177+
=== Fixing API compatibility check failures
178+
179+
Log4j uses the
180+
https://github.com/bndtools/bnd/tree/master/maven-plugins/bnd-baseline-maven-plugin[BND Baseline Maven Plugin]
181+
to enforce its
182+
https://semver.org/[semantic versioning policy].
183+
Following the
184+
https://bnd.bndtools.org/chapters/170-versioning.html#best-practices[OSGi versioning best practices], both Log4j artifacts and packages are versioned.
185+
If you modify Log4j's public API, a BND Baseline error like the following will occur:
186+
187+
[source]
188+
----
189+
Name Type Delta New Old Suggest If Prov.
190+
org.apache.logging.foo PACKAGE UNCHANGED 2.1.0 2.1.0 ok -
191+
* org.apache.logging.foo.bar PACKAGE MINOR 2.3.4 2.3.4 2.4.0 -
192+
MINOR PACKAGE org.apache.logging.foo.bar
193+
...
194+
----
195+
196+
The solution of the error depends on the change kind (`Delta`):
197+
198+
[#development-api-compatibility-micro]
199+
`MICRO`::
200+
+
201+
For patch level changes modify the `package-info.java` file of the `org.apache.logging.foo.bar` package and update the `@Version` annotation to the number suggested by BND: increment just the patch number.
202+
+
203+
[source,java]
204+
----
205+
@Version("2.3.5")
206+
package org.apache.logging.foo.bar;
207+
----
208+
209+
[#development-api-compatibility-minor]
210+
`MINOR`::
211+
+
212+
Changes of type `MINOR` require more work:
213+
+
214+
--
215+
* Make sure that the current Log4j version is a minor upgrade over the last released version.
216+
If that is not the case (e.g., it is `2.34.5-SNAPSHOT`) modify the `<revision>` property in the main POM file (e.g., change it to `2.35.0-SNAPSHOT`).
217+
* Make sure to add a
218+
https://logging.apache.org/log4j/tools/log4j-changelog.html#changelog-entry-file[changelog entry]
219+
of type `added`, `changed` or `deprecated` to your PR.
220+
* As in the
221+
<<development-api-compatibility-micro,`MICRO` case>>
222+
modify the `package-info.java` file of the package and update the `@Version` annotation to the **next Log4j version** (`2.35.0` in the example) and **not** the minimal version number suggested by BND.
223+
The purpose of this policy is to have an alignment between package versions and the last Log4j version, where an API change occurred.
224+
--
225+
226+
[#development-api-compatibility-major]
227+
`MAJOR`::
228+
+
229+
Changes of type `MAJOR` (i.e. breaking changes) are not accepted in the `2.x` branch.
230+
If you believe it is not a breaking change (e.g., you removed a class **documented** as private), the development team will guide you on how to solve it.

log4j-1.2-api/pom.xml

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,93 +43,100 @@
4343
com.sun.jdmk.comm;resolution:=optional,
4444
<!-- JMS is optional -->
4545
javax.jms;version="[1.1,3)";resolution:=optional,
46-
<!-- Log4j Core is optional -->
47-
org.apache.logging.log4j.core.*;resolution:=optional
4846
</bnd-extra-package-options>
47+
<bnd-extra-module-options>
48+
<!-- Log4j Core is optional -->
49+
org.apache.logging.log4j.core;static=true
50+
</bnd-extra-module-options>
4951
<Fragment-Host>org.apache.logging.log4j.core</Fragment-Host>
50-
<!-- we have an `bnd.bnd` file to override the parent's defaults -->
5152
</properties>
5253

5354
<dependencies>
55+
5456
<!-- Used for JMS appenders (needs an implementation of course) -->
5557
<dependency>
5658
<groupId>javax.jms</groupId>
5759
<artifactId>javax.jms-api</artifactId>
5860
<scope>provided</scope>
59-
<optional>true</optional>
6061
</dependency>
61-
<!-- Log4j Runtime -->
62+
63+
<dependency>
64+
<groupId>org.jspecify</groupId>
65+
<artifactId>jspecify</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
6269
<dependency>
6370
<groupId>org.apache.logging.log4j</groupId>
6471
<artifactId>log4j-api</artifactId>
6572
</dependency>
73+
6674
<dependency>
6775
<groupId>org.apache.logging.log4j</groupId>
6876
<artifactId>log4j-core</artifactId>
6977
<optional>true</optional>
7078
</dependency>
79+
7180
<dependency>
7281
<groupId>org.apache.logging.log4j</groupId>
7382
<artifactId>log4j-api-test</artifactId>
7483
<scope>test</scope>
7584
</dependency>
85+
7686
<dependency>
7787
<groupId>org.apache.logging.log4j</groupId>
7888
<artifactId>log4j-core-test</artifactId>
7989
<scope>test</scope>
8090
</dependency>
91+
8192
<dependency>
8293
<groupId>org.awaitility</groupId>
8394
<artifactId>awaitility</artifactId>
8495
<scope>test</scope>
8596
</dependency>
97+
8698
<dependency>
8799
<groupId>commons-io</groupId>
88100
<artifactId>commons-io</artifactId>
89101
<scope>test</scope>
90102
</dependency>
103+
91104
<dependency>
92105
<groupId>org.apache.commons</groupId>
93106
<artifactId>commons-lang3</artifactId>
94107
<scope>test</scope>
95108
</dependency>
109+
96110
<dependency>
97111
<groupId>com.fasterxml.jackson.dataformat</groupId>
98112
<artifactId>jackson-dataformat-xml</artifactId>
99113
<scope>test</scope>
100114
</dependency>
115+
116+
<!-- JUnit -->
101117
<dependency>
102118
<groupId>org.junit.jupiter</groupId>
103119
<artifactId>junit-jupiter-engine</artifactId>
104120
<scope>test</scope>
105121
</dependency>
122+
106123
<dependency>
107124
<groupId>org.junit.jupiter</groupId>
108125
<artifactId>junit-jupiter-params</artifactId>
109126
<scope>test</scope>
110127
</dependency>
111-
<!-- JUnit -->
112128
<dependency>
113-
<groupId>org.junit.vintage</groupId>
114-
<artifactId>junit-vintage-engine</artifactId>
129+
<groupId>org.hamcrest</groupId>
130+
<artifactId>hamcrest</artifactId>
115131
<scope>test</scope>
116132
</dependency>
133+
117134
<dependency>
118135
<groupId>org.mockito</groupId>
119136
<artifactId>mockito-core</artifactId>
120137
<scope>test</scope>
121138
</dependency>
122-
<!-- 1.2 tests -->
123-
<dependency>
124-
<groupId>oro</groupId>
125-
<artifactId>oro</artifactId>
126-
<scope>test</scope>
127-
</dependency>
128-
<dependency>
129-
<groupId>org.apache.velocity</groupId>
130-
<artifactId>velocity</artifactId>
131-
<scope>test</scope>
132-
</dependency>
139+
133140
</dependencies>
134141

135142
<profiles>

log4j-1.2-api/src/main/java/org/apache/log4j/Level.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ protected Level(
115115
final String levelStr,
116116
final int syslogEquivalent,
117117
final org.apache.logging.log4j.Level version2Equivalent) {
118-
super(level, levelStr, syslogEquivalent);
119-
this.version2Level = version2Equivalent != null ? version2Equivalent : OptionConverter.createLevel(this);
118+
super(level, levelStr, syslogEquivalent, version2Equivalent);
120119
}
121120

122121
/**
@@ -222,6 +221,7 @@ private void readObject(final ObjectInputStream s) throws IOException, ClassNotF
222221
if (levelStr == null) {
223222
levelStr = Strings.EMPTY;
224223
}
224+
version2Level = OptionConverter.createLevel(this);
225225
}
226226

227227
/**

log4j-1.2-api/src/main/java/org/apache/log4j/Priority.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.log4j;
1818

19+
import org.apache.log4j.helpers.OptionConverter;
20+
1921
/**
2022
* <em style="color:#A44">Refrain from using this class directly, use
2123
* the {@link Level} class instead.</em>
@@ -64,31 +66,31 @@ public class Priority {
6466
* @deprecated Use {@link Level#FATAL} instead.
6567
*/
6668
@Deprecated
67-
public static final Priority FATAL = new Level(FATAL_INT, "FATAL", 0);
69+
public static final Priority FATAL = new Priority(FATAL_INT, "FATAL", 0, org.apache.logging.log4j.Level.FATAL);
6870

6971
/**
7072
* @deprecated Use {@link Level#ERROR} instead.
7173
*/
7274
@Deprecated
73-
public static final Priority ERROR = new Level(ERROR_INT, "ERROR", 3);
75+
public static final Priority ERROR = new Priority(ERROR_INT, "ERROR", 3, org.apache.logging.log4j.Level.ERROR);
7476

7577
/**
7678
* @deprecated Use {@link Level#WARN} instead.
7779
*/
7880
@Deprecated
79-
public static final Priority WARN = new Level(WARN_INT, "WARN", 4);
81+
public static final Priority WARN = new Priority(WARN_INT, "WARN", 4, org.apache.logging.log4j.Level.WARN);
8082

8183
/**
8284
* @deprecated Use {@link Level#INFO} instead.
8385
*/
8486
@Deprecated
85-
public static final Priority INFO = new Level(INFO_INT, "INFO", 6);
87+
public static final Priority INFO = new Priority(INFO_INT, "INFO", 6, org.apache.logging.log4j.Level.INFO);
8688

8789
/**
8890
* @deprecated Use {@link Level#DEBUG} instead.
8991
*/
9092
@Deprecated
91-
public static final Priority DEBUG = new Level(DEBUG_INT, "DEBUG", 7);
93+
public static final Priority DEBUG = new Priority(DEBUG_INT, "DEBUG", 7, org.apache.logging.log4j.Level.DEBUG);
9294

9395
/*
9496
* These variables should be private but were not in Log4j 1.2 so are left the same way here.
@@ -102,9 +104,7 @@ public class Priority {
102104
* Default constructor for deserialization.
103105
*/
104106
protected Priority() {
105-
level = DEBUG_INT;
106-
levelStr = "DEBUG";
107-
syslogEquivalent = 7;
107+
this(DEBUG_INT, "DEBUG", 7, org.apache.logging.log4j.Level.DEBUG);
108108
}
109109

110110
/**
@@ -114,9 +114,18 @@ protected Priority() {
114114
* @param syslogEquivalent The equivalent syslog value.
115115
*/
116116
protected Priority(final int level, final String levelStr, final int syslogEquivalent) {
117+
this(level, levelStr, syslogEquivalent, null);
118+
}
119+
120+
Priority(
121+
final int level,
122+
final String levelStr,
123+
final int syslogEquivalent,
124+
final org.apache.logging.log4j.Level version2Equivalent) {
117125
this.level = level;
118126
this.levelStr = levelStr;
119127
this.syslogEquivalent = syslogEquivalent;
128+
this.version2Level = version2Equivalent != null ? version2Equivalent : OptionConverter.createLevel(this);
120129
}
121130

122131
/**
@@ -229,7 +238,8 @@ public static Priority toPriority(final int val) {
229238
*/
230239
@Deprecated
231240
public static Priority toPriority(final int val, final Priority defaultPriority) {
232-
return Level.toLevel(val, (Level) defaultPriority);
241+
Level result = Level.toLevel(val, null);
242+
return result == null ? defaultPriority : result;
233243
}
234244

235245
/**
@@ -240,6 +250,7 @@ public static Priority toPriority(final int val, final Priority defaultPriority)
240250
*/
241251
@Deprecated
242252
public static Priority toPriority(final String sArg, final Priority defaultPriority) {
243-
return Level.toLevel(sArg, (Level) defaultPriority);
253+
Level result = Level.toLevel(sArg, null);
254+
return result == null ? defaultPriority : result;
244255
}
245256
}

log4j-1.2-api/src/main/java/org/apache/log4j/bridge/FilterAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static Filter addFilter(final Filter first, final Filter second) {
6969
if (first instanceof FilterWrapper && ((FilterWrapper) first).getFilter() instanceof CompositeFilter) {
7070
composite = (CompositeFilter) ((FilterWrapper) first).getFilter();
7171
} else {
72-
composite = CompositeFilter.createFilters(new org.apache.logging.log4j.core.Filter[] {adapt(first)});
72+
composite = CompositeFilter.createFilters(adapt(first));
7373
}
7474
return FilterWrapper.adapt(composite.addFilter(adapt(second)));
7575
}

log4j-1.2-api/src/main/java/org/apache/log4j/builders/filter/StringMatchFilterBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private Filter createFilter(final String text, final boolean acceptOnMatch) {
8686
? org.apache.logging.log4j.core.Filter.Result.ACCEPT
8787
: org.apache.logging.log4j.core.Filter.Result.DENY;
8888
return FilterWrapper.adapt(StringMatchFilter.newBuilder()
89-
.setMatchString(text)
89+
.setText(text)
9090
.setOnMatch(onMatch)
9191
.setOnMismatch(org.apache.logging.log4j.core.Filter.Result.NEUTRAL)
9292
.build());

log4j-1.2-api/src/main/java/org/apache/log4j/xml/XmlConfiguration.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ public class XmlConfiguration extends Log4j1Configuration {
9090
private static final String INTERNAL_DEBUG_ATTR = "debug";
9191
private static final String THRESHOLD_ATTR = "threshold";
9292
private static final String EMPTY_STR = "";
93-
private static final Class<?>[] ONE_STRING_PARAM = new Class[] {String.class};
9493
private static final String dbfKey = "javax.xml.parsers.DocumentBuilderFactory";
9594
private static final String THROWABLE_RENDERER_TAG = "throwableRenderer";
9695

@@ -504,7 +503,6 @@ private void parseErrorHandler(Element element, Appender appender) {
504503
/**
505504
* Used internally to parse a filter element.
506505
* @param filterElement The Filter Element.
507-
* @return The Filter.
508506
*/
509507
public void addFilter(final AtomicReference<Filter> ref, final Element filterElement) {
510508
final Filter value = parseFilters(filterElement);

log4j-1.2-api/src/test/java/org/apache/log4j/CallerInformationTest.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,46 @@
1616
*/
1717
package org.apache.log4j;
1818

19-
import static org.junit.Assert.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
2020

2121
import java.util.List;
2222
import org.apache.logging.log4j.core.test.appender.ListAppender;
23-
import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
24-
import org.junit.ClassRule;
25-
import org.junit.Test;
23+
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
24+
import org.apache.logging.log4j.core.test.junit.Named;
25+
import org.junit.jupiter.api.Test;
2626

27+
// config from log4j-core test-jar
28+
@LoggerContextSource(value = "log4j2-calling-class.xml")
2729
public class CallerInformationTest {
2830

29-
// config from log4j-core test-jar
30-
private static final String CONFIG = "log4j2-calling-class.xml";
31-
32-
@ClassRule
33-
public static final LoggerContextRule ctx = new LoggerContextRule(CONFIG);
34-
3531
@Test
36-
public void testClassLogger() {
37-
final ListAppender app = ctx.getListAppender("Class").clear();
32+
public void testClassLogger(@Named("Class") final ListAppender app) {
33+
app.clear();
3834
final Logger logger = Logger.getLogger("ClassLogger");
3935
logger.info("Ignored message contents.");
4036
logger.warn("Verifying the caller class is still correct.");
4137
logger.error("Hopefully nobody breaks me!");
4238
final List<String> messages = app.getMessages();
43-
assertEquals("Incorrect number of messages.", 3, messages.size());
39+
40+
assertEquals(3, messages.size(), "Incorrect number of messages.");
4441
for (final String message : messages) {
45-
assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
42+
assertEquals(this.getClass().getName(), message, "Incorrect caller class name.");
4643
}
4744
}
4845

4946
@Test
50-
public void testMethodLogger() {
51-
final ListAppender app = ctx.getListAppender("Method").clear();
47+
public void testMethodLogger(@Named("Method") final ListAppender app) {
48+
app.clear();
5249
final Logger logger = Logger.getLogger("MethodLogger");
5350
logger.info("More messages.");
5451
logger.warn("CATASTROPHE INCOMING!");
5552
logger.error("ZOMBIES!!!");
5653
logger.warn("brains~~~");
5754
logger.info("Itchy. Tasty.");
5855
final List<String> messages = app.getMessages();
59-
assertEquals("Incorrect number of messages.", 5, messages.size());
56+
assertEquals(5, messages.size(), "Incorrect number of messages.");
6057
for (final String message : messages) {
61-
assertEquals("Incorrect caller method name.", "testMethodLogger", message);
58+
assertEquals("testMethodLogger", message, "Incorrect caller method name.");
6259
}
6360
}
6461
}

0 commit comments

Comments
 (0)