Skip to content

Commit 4905310

Browse files
authored
Merge branch '2.x' into 2.x
2 parents 5584f8c + 58bd98e commit 4905310

File tree

34 files changed

+405
-231
lines changed

34 files changed

+405
-231
lines changed

.asf.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ github:
4040
issues: true
4141
discussions: true
4242
projects: true
43-
del_branch_on_merge: true
4443
autolink_jira:
4544
- LOG4J2
4645
labels:
@@ -56,6 +55,16 @@ github:
5655
- api
5756
- syslog
5857

58+
# Pull Request settings:
59+
# https://github.com/apache/infrastructure-asfyaml#pull-request-settings
60+
pull_requests:
61+
# allow auto-merge
62+
allow_auto_merge: true
63+
# enable updating head branches of pull requests
64+
allow_update_branch: true
65+
# auto-delete head branches after being merged
66+
del_branch_on_merge: true
67+
5968
# Enforce squashing while merging PRs.
6069
# Otherwise, the git log gets polluted severely.
6170
enabled_merge_buttons:

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
with:
8383
nexus-url: ${{ needs.deploy-release.result == 'success' && needs.deploy-release.outputs.nexus-url || 'https://repository.apache.org/content/groups/snapshots' }}
8484
# Encode the `runs-on` input as JSON array
85-
runs-on: '["ubuntu-latest", "macos-latest", "windows-latest"]'
85+
runs-on: '["ubuntu-latest", "macos-latest"]'
8686

8787
# Run integration-tests automatically after a snapshot or RC is published
8888
integration-test:

log4j-1.2-api/src/main/java/org/apache/log4j/rewrite/MapRewritePolicy.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ public LoggingEvent rewrite(final LoggingEvent source) {
105105
.setThrown(source.getThrowableInformation().getThrowable())
106106
.setTimeMillis(source.getTimeStamp())
107107
.setNanoTime(0)
108-
.setThrownProxy(null)
109108
.build();
110109
}
111110
return new LogEventAdapter(event);

log4j-1.2-api/src/main/java/org/apache/log4j/rewrite/PropertyRewritePolicy.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ public LoggingEvent rewrite(final LoggingEvent source) {
110110
.setThrown(source.getThrowableInformation().getThrowable())
111111
.setTimeMillis(source.getTimeStamp())
112112
.setNanoTime(0)
113-
.setThrownProxy(null)
114113
.build();
115114
}
116115
return new LogEventAdapter(event);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.logging.log4j.status;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
22+
import java.io.ByteArrayOutputStream;
23+
import java.io.PrintStream;
24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
28+
class StatusLoggerTest {
29+
private final PrintStream origOut = System.out;
30+
private final PrintStream origErr = System.err;
31+
private ByteArrayOutputStream outBuf;
32+
private ByteArrayOutputStream errBuf;
33+
34+
@BeforeEach
35+
void setupStreams() {
36+
outBuf = new ByteArrayOutputStream();
37+
errBuf = new ByteArrayOutputStream();
38+
System.setOut(new PrintStream(outBuf));
39+
System.setErr(new PrintStream(errBuf));
40+
}
41+
42+
@AfterEach
43+
void resetStreams() {
44+
System.setOut(origOut);
45+
System.setErr(origErr);
46+
}
47+
48+
@Test
49+
void status_logger_writes_to_stderr_by_default() {
50+
StatusLogger statusLogger = new StatusLogger();
51+
statusLogger.error("Test message");
52+
53+
assertEquals("", outBuf.toString());
54+
assertThat(errBuf.toString()).contains("Test message");
55+
}
56+
}

log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ public <S> void forEachParameter(final ParameterConsumer<S> action, final S stat
128128

129129
@Override
130130
public Message memento() {
131-
return new ObjectMessage(obj);
131+
Message message = new ObjectMessage(obj);
132+
// Since `toString()` methods are not always pure functions and might depend on the thread and other context
133+
// values, we format the message and cache the result.
134+
message.getFormattedMessage();
135+
return message;
132136
}
133137

134138
/**

log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableParameterizedMessage.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ public <S> void forEachParameter(final ParameterConsumer<S> action, final S stat
114114

115115
@Override
116116
public Message memento() {
117-
return new ParameterizedMessage(messagePattern, getTrimmedParams());
117+
Message message = new ParameterizedMessage(messagePattern, getTrimmedParams());
118+
// Since `toString()` methods are not always pure functions and might depend on the thread and other context
119+
// values, we format the message and cache the result.
120+
message.getFormattedMessage();
121+
return message;
118122
}
119123

120124
private void init(final String messagePattern, final int argCount, final Object[] args) {

log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableSimpleMessage.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ public <S> void forEachParameter(final ParameterConsumer<S> action, final S stat
8585

8686
@Override
8787
public Message memento() {
88-
return new SimpleMessage(charSequence);
88+
SimpleMessage message = new SimpleMessage(charSequence);
89+
// Since `toString()` methods are not always pure functions and might depend on the thread and other context
90+
// values, we format the message and cache the result.
91+
message.getFormattedMessage();
92+
return message;
8993
}
9094

9195
// CharSequence impl

log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ private static final class InstanceHolder {
531531
StatusLogger.class.getSimpleName(),
532532
ParameterizedNoReferenceMessageFactory.INSTANCE,
533533
Config.getInstance(),
534-
new StatusConsoleListener(requireNonNull(Config.getInstance().fallbackListenerLevel)));
534+
new StatusConsoleListener(requireNonNull(Config.getInstance().fallbackListenerLevel), System.err));
535535
}
536536

537537
/**

log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/appender/ListAppender.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
3636
import org.apache.logging.log4j.core.config.plugins.PluginElement;
3737
import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
38-
import org.apache.logging.log4j.core.impl.MutableLogEvent;
3938
import org.apache.logging.log4j.core.layout.SerializedLayout;
4039
import org.awaitility.Awaitility;
4140

@@ -121,12 +120,7 @@ public ListAppender(
121120
public void append(final LogEvent event) {
122121
final Layout<? extends Serializable> layout = getLayout();
123122
if (layout == null) {
124-
if (event instanceof MutableLogEvent) {
125-
// must take snapshot or subsequent calls to logger.log() will modify this event
126-
events.add(((MutableLogEvent) event).createMemento());
127-
} else {
128-
events.add(event);
129-
}
123+
events.add(event.toImmutable());
130124
} else if (layout instanceof SerializedLayout) {
131125
final byte[] header = layout.getHeader();
132126
final byte[] content = layout.toByteArray(event);

0 commit comments

Comments
 (0)