Skip to content

Commit

Permalink
[pinpoint-apm#11290] log4j-it, add test for full-pattern replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
yjqg6666 committed Jul 26, 2024
1 parent 754b773 commit 0410956
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2024 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.it.plugin.log4j;

import com.navercorp.pinpoint.it.plugin.utils.AgentPath;
import com.navercorp.pinpoint.it.plugin.utils.PluginITConstants;
import com.navercorp.pinpoint.test.plugin.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

@PluginForkedTest
@PinpointAgent(AgentPath.PATH)
@Dependency({"log4j:log4j:[1.2.16,)", PluginITConstants.VERSION})
@ImportPlugin({"com.navercorp.pinpoint:pinpoint-log4j-plugin"})
@PinpointConfig("pinpoint-spring-bean-test.config")
@TransformInclude("org.apache.log4j.")
@JvmArgument("-Dprofiler.log4j.logging.pattern.full_replace.with=IT TxId:%X{PtxId} %m")
public class Log4jFullReplaceIT extends Log4jTestBase {

@Test
public void test() {
checkMDC();
}

@Test
public void patternUpdate() {
String log = checkPatternReplace();
Assertions.assertTrue(log.contains("IT"), "contains full-replace string IT");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected void checkMDC() {
Assertions.assertNotNull(MDC.get("PspanId"), "spanId");
}

protected void checkPatternReplace() {
protected String checkPatternReplace() {
final String msg = "pattern";


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

Assertions.assertNotNull(logger, "logger null");
checkVersion(logger);
return log;
}

private void checkVersion(Logger logger) {
Expand Down

0 comments on commit 0410956

Please sign in to comment.