1717import java .util .List ;
1818import java .util .ServiceLoader ;
1919import java .util .function .Function ;
20+ import java .util .function .Predicate ;
2021import java .util .function .Supplier ;
2122import java .util .jar .Attributes ;
2223import java .util .jar .Manifest ;
24+ import java .util .logging .LogManager ;
25+ import java .util .logging .LogRecord ;
26+ import java .util .logging .Logger ;
2327import java .util .stream .Stream ;
2428
2529import org .jboss .shrinkwrap .api .exporter .ExplodedExporter ;
5862public class QuarkusDevModeTest
5963 implements BeforeEachCallback , AfterEachCallback , TestInstanceFactory {
6064
65+ private static final Logger rootLogger ;
66+
6167 static {
6268 System .setProperty ("java.util.logging.manager" , "org.jboss.logmanager.LogManager" );
69+ rootLogger = LogManager .getLogManager ().getLogger ("" );
6370 }
6471
6572 private DevModeMain devModeMain ;
6673 private Path deploymentDir ;
6774 private Supplier <JavaArchive > archiveProducer ;
6875 private String logFileName ;
76+ private InMemoryLogHandler inMemoryLogHandler = new InMemoryLogHandler ((r ) -> false );
6977
7078 private Path deploymentSourcePath ;
7179 private Path deploymentResourcePath ;
@@ -97,6 +105,15 @@ public QuarkusDevModeTest setLogFileName(String logFileName) {
97105 return this ;
98106 }
99107
108+ public QuarkusDevModeTest setLogRecordPredicate (Predicate <LogRecord > predicate ) {
109+ this .inMemoryLogHandler = new InMemoryLogHandler (predicate );
110+ return this ;
111+ }
112+
113+ public List <LogRecord > getLogRecords () {
114+ return inMemoryLogHandler .records ;
115+ }
116+
100117 public Object createTestInstance (TestInstanceFactoryContext factoryContext , ExtensionContext extensionContext )
101118 throws TestInstantiationException {
102119 try {
@@ -110,6 +127,7 @@ public Object createTestInstance(TestInstanceFactoryContext factoryContext, Exte
110127
111128 @ Override
112129 public void beforeEach (ExtensionContext extensionContext ) throws Exception {
130+ rootLogger .addHandler (inMemoryLogHandler );
113131 if (archiveProducer == null ) {
114132 throw new RuntimeException ("QuarkusDevModeTest does not have archive producer set" );
115133 }
@@ -174,6 +192,7 @@ public void afterEach(ExtensionContext extensionContext) throws Exception {
174192 FileUtil .deleteDirectory (deploymentDir );
175193 }
176194 }
195+ rootLogger .removeHandler (inMemoryLogHandler );
177196 }
178197
179198 private DevModeContext exportArchive (Path deploymentDir , Path testSourceDir ) {
0 commit comments