Skip to content

Commit 9c46a25

Browse files
authored
Use more human-readable appender format for STs logs (#11377)
Signed-off-by: Jakub Stejskal <xstejs24@gmail.com>
1 parent c3513c1 commit 9c46a25

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

systemtest/src/main/resources/log4j2.properties

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ name = STConfig
33
appender.console.type = Console
44
appender.console.name = STDOUT
55
appender.console.layout.type = PatternLayout
6-
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss}{GMT} [%thread] %highlight{%-5p} [%c{1}:%L] %m%n
7-
6+
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss}{GMT} [T-%.3T] %highlight{%-5p}%notEmpty{[%X{testClass}]}%notEmpty{[%X{testMethod}]} [%c{1}:%L] %m%n
87
appender.rolling.type = RollingFile
98
appender.rolling.name = RollingFile
109
appender.rolling.fileName = ${env:TEST_LOG_DIR:-target/logs}/strimzi-debug-${env:BUILD_ID:-0}.log
@@ -15,7 +14,7 @@ appender.rolling.policies.size.size=100MB
1514
appender.rolling.strategy.type = DefaultRolloverStrategy
1615
appender.rolling.strategy.max = 5
1716
appender.rolling.layout.type = PatternLayout
18-
appender.rolling.layout.pattern=%d{yyyy-MM-dd HH:mm:ss}{GMT} %-5p [%c{1}:%L] %m%n
17+
appender.rolling.layout.pattern=%d{yyyy-MM-dd HH:mm:ss}{GMT} [T-%.3T] %highlight{%-5p}%notEmpty{[%X{testClass}]}%notEmpty{[%X{testMethod}]} [%c{1}:%L] %m%n
1918

2019
rootLogger.level = ${env:STRIMZI_TEST_ROOT_LOG_LEVEL:-DEBUG}
2120
rootLogger.appenderRef.console.ref = STDOUT

systemtest/src/test/java/io/strimzi/systemtest/AbstractST.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.strimzi.test.k8s.KubeClusterResource;
1818
import org.apache.logging.log4j.LogManager;
1919
import org.apache.logging.log4j.Logger;
20+
import org.apache.logging.log4j.ThreadContext;
2021
import org.junit.jupiter.api.AfterAll;
2122
import org.junit.jupiter.api.AfterEach;
2223
import org.junit.jupiter.api.BeforeAll;
@@ -138,6 +139,14 @@ protected void beforeAllMayOverride() {
138139

139140
@BeforeEach
140141
void setUpTestCase(ExtensionContext extensionContext) {
142+
// Check if we execute tests in parallel to update logger appender dynamically
143+
boolean parallelEnabled = Boolean.getBoolean("junit.jupiter.execution.parallel.enabled");
144+
if (extensionContext.getTestClass().isPresent() && parallelEnabled) {
145+
ThreadContext.put("testClass", extensionContext.getTestClass().get().getSimpleName());
146+
}
147+
if (extensionContext.getTestMethod().isPresent() && parallelEnabled) {
148+
ThreadContext.put("testMethod", extensionContext.getTestMethod().get().getName());
149+
}
141150
ResourceManager.setTestContext(extensionContext);
142151
LOGGER.debug(String.join("", Collections.nCopies(76, "=")));
143152
LOGGER.debug("———————————— {}@Before Each - Setup TestCase environment ———————————— ", StUtils.removePackageName(this.getClass().getName()));
@@ -147,6 +156,11 @@ void setUpTestCase(ExtensionContext extensionContext) {
147156

148157
@BeforeAll
149158
void setUpTestSuite(ExtensionContext extensionContext) {
159+
// Check if we execute tests in parallel to update logger appender dynamically
160+
boolean parallelEnabled = Boolean.getBoolean("junit.jupiter.execution.parallel.enabled");
161+
if (extensionContext.getTestClass().isPresent() && parallelEnabled) {
162+
ThreadContext.put("testClass", extensionContext.getTestClass().get().getSimpleName());
163+
}
150164
ResourceManager.setTestContext(extensionContext);
151165
LOGGER.debug(String.join("", Collections.nCopies(76, "=")));
152166
LOGGER.debug("———————————— {}@Before All - Setup TestSuite environment ———————————— ", StUtils.removePackageName(this.getClass().getName()));
@@ -170,6 +184,7 @@ void tearDownTestCase(ExtensionContext extensionContext) throws Exception {
170184
} finally {
171185
afterEachMayOverride();
172186
afterEachMustExecute();
187+
ThreadContext.remove("testMethod");
173188
}
174189
}
175190

@@ -180,5 +195,6 @@ void tearDownTestSuite(ExtensionContext extensionContext) {
180195
LOGGER.debug("———————————— {}@After All - Clean up after TestSuite ———————————— ", StUtils.removePackageName(this.getClass().getName()));
181196
afterAllMayOverride();
182197
afterAllMustExecute();
198+
ThreadContext.remove("testClass");
183199
}
184200
}

0 commit comments

Comments
 (0)