Skip to content

Commit b5723bf

Browse files
committed
[#11290] log4j-it, add test for full-pattern replacement
1 parent a047b0b commit b5723bf

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2018 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.navercorp.pinpoint.it.plugin.log4j;
17+
18+
import com.navercorp.pinpoint.it.plugin.utils.AgentPath;
19+
import com.navercorp.pinpoint.it.plugin.utils.PluginITConstants;
20+
import com.navercorp.pinpoint.test.plugin.*;
21+
import org.junit.jupiter.api.Assertions;
22+
import org.junit.jupiter.api.Test;
23+
24+
@PluginForkedTest
25+
@PinpointAgent(AgentPath.PATH)
26+
@Dependency({"log4j:log4j:[1.2.16,)", PluginITConstants.VERSION})
27+
@ImportPlugin({"com.navercorp.pinpoint:pinpoint-log4j-plugin"})
28+
@PinpointConfig("pinpoint-spring-bean-test.config")
29+
@TransformInclude("org.apache.log4j.")
30+
@JvmArgument("-Dprofiler.log4j.logging.pattern.full_replace.with=IT TxId:%X{PtxId} %m")
31+
public class Log4jFullReplaceIT extends Log4jTestBase {
32+
33+
@Test
34+
public void test() {
35+
checkMDC();
36+
}
37+
38+
@Test
39+
public void patternUpdate() {
40+
String log = checkPatternReplace();
41+
Assertions.assertTrue(log.contains("IT"), "contains full-replace string IT");
42+
}
43+
44+
}

agent-module/plugins-it/log4j-it/src/test/java/com/navercorp/pinpoint/it/plugin/log4j/Log4jTestBase.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected void checkMDC() {
3434
Assertions.assertNotNull(MDC.get("PspanId"), "spanId");
3535
}
3636

37-
protected void checkPatternReplace() {
37+
protected String checkPatternReplace() {
3838
final String msg = "pattern";
3939

4040

@@ -54,6 +54,7 @@ public void run() {
5454

5555
Assertions.assertNotNull(logger, "logger null");
5656
checkVersion(logger);
57+
return log;
5758
}
5859

5960
private void checkVersion(Logger logger) {

0 commit comments

Comments
 (0)