Skip to content

Commit

Permalink
Don't queue up log messages when the process isn't running a Quarkus …
Browse files Browse the repository at this point in the history
…application

Fixes: quarkusio#14295
  • Loading branch information
geoand committed Jan 15, 2021
1 parent fe70f17 commit 1a416ba
Showing 1 changed file with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,41 @@
public final class InitialConfigurator implements EmbeddedConfigurator {

public static final DelayedHandler DELAYED_HANDLER;
private static final Handler[] HANDLER_ARRAY;

static {
//a hack around class loading
//this is always loaded in the root class loader with jboss-logmanager,
//however it may also be loaded in an isolated CL when running in dev
//or test mode. If it is in an isolated CL we load the handler from
//the class on the system class loader so they are equal
//TODO: should this class go in its own module and be excluded from isolated class loading?
DelayedHandler handler = new DelayedHandler();
boolean isQuarkusApplication = true;
DelayedHandler delayedHandler = new DelayedHandler();
ClassLoader cl = InitialConfigurator.class.getClassLoader();
try {
Class<?> root = Class.forName(InitialConfigurator.class.getName(), false, ClassLoader.getSystemClassLoader());
if (root.getClassLoader() != cl) {
handler = (DelayedHandler) root.getDeclaredField("DELAYED_HANDLER").get(null);
// Check and see if this is a Quarkus application. If it is, this class has already been loaded
Class.forName("io.quarkus.runner.ApplicationImpl", false, cl);

//a hack around class loading
//this is always loaded in the root class loader with jboss-logmanager,
//however it may also be loaded in an isolated CL when running in dev
//or test mode. If it is in an isolated CL we load the handler from
//the class on the system class loader so they are equal
//TODO: should this class go in its own module and be excluded from isolated class loading?
try {
Class<?> root = Class.forName(InitialConfigurator.class.getName(), false, ClassLoader.getSystemClassLoader());
if (root.getClassLoader() != cl) {
delayedHandler = (DelayedHandler) root.getDeclaredField("DELAYED_HANDLER").get(null);
}
} catch (Exception e) {
//ignore, happens on native image build
}
} catch (Exception e) {
//ignore, happens on native image build
} catch (ClassNotFoundException e) {
isQuarkusApplication = false;
}
Handler[] handlerArray;
if (isQuarkusApplication) {
handlerArray = new Handler[] { delayedHandler };
} else {
handlerArray = EmbeddedConfigurator.NO_HANDLERS;
}
DELAYED_HANDLER = handler;
HANDLER_ARRAY = handlerArray;
DELAYED_HANDLER = delayedHandler;
}

@Override
Expand All @@ -54,7 +70,7 @@ public Handler[] getHandlersOf(final String loggerName) {
createDefaultHandler()
};
} else {
return new Handler[] { DELAYED_HANDLER };
return HANDLER_ARRAY;
}
} else {
return EmbeddedConfigurator.NO_HANDLERS;
Expand Down

0 comments on commit 1a416ba

Please sign in to comment.