Skip to content

Commit

Permalink
Don't setup logging on failure in dev mode
Browse files Browse the repository at this point in the history
Dev mode already sets up logging, so this results in every line being
printed twice after a startup failure (depending on where in the startup
sequence things actually failed).
  • Loading branch information
stuartwdouglas committed Jul 29, 2021
1 parent 856d0c3 commit 8ed5852
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,17 +298,23 @@ void build(List<StaticBytecodeRecorderBuildItem> staticInitTasks,
cb = tryBlock.addCatch(Throwable.class);

// an exception was thrown before logging was actually setup, we simply dump everything to the console
ResultHandle delayedHandler = cb
.readStaticField(FieldDescriptor.of(InitialConfigurator.class, "DELAYED_HANDLER", QuarkusDelayedHandler.class));
ResultHandle isActivated = cb.invokeVirtualMethod(ofMethod(QuarkusDelayedHandler.class, "isActivated", boolean.class),
delayedHandler);
BytecodeCreator isActivatedFalse = cb.ifNonZero(isActivated).falseBranch();
ResultHandle handlersArray = isActivatedFalse.newArray(Handler.class, 1);
isActivatedFalse.writeArrayValue(handlersArray, 0, isActivatedFalse.newInstance(ofConstructor(ConsoleHandler.class)));
isActivatedFalse.invokeVirtualMethod(
ofMethod(QuarkusDelayedHandler.class, "setHandlers", Handler[].class, Handler[].class),
delayedHandler, handlersArray);
isActivatedFalse.breakScope();
// we don't do this for dev mode, as on startup failure dev mode sets up its own logging
if (launchMode.getLaunchMode() != LaunchMode.DEVELOPMENT) {
ResultHandle delayedHandler = cb
.readStaticField(
FieldDescriptor.of(InitialConfigurator.class, "DELAYED_HANDLER", QuarkusDelayedHandler.class));
ResultHandle isActivated = cb.invokeVirtualMethod(
ofMethod(QuarkusDelayedHandler.class, "isActivated", boolean.class),
delayedHandler);
BytecodeCreator isActivatedFalse = cb.ifNonZero(isActivated).falseBranch();
ResultHandle handlersArray = isActivatedFalse.newArray(Handler.class, 1);
isActivatedFalse.writeArrayValue(handlersArray, 0,
isActivatedFalse.newInstance(ofConstructor(ConsoleHandler.class)));
isActivatedFalse.invokeVirtualMethod(
ofMethod(QuarkusDelayedHandler.class, "setHandlers", Handler[].class, Handler[].class),
delayedHandler, handlersArray);
isActivatedFalse.breakScope();
}

cb.invokeVirtualMethod(ofMethod(StartupContext.class, "close", void.class), startupContext);
cb.throwException(RuntimeException.class, "Failed to start quarkus", cb.getCaughtException());
Expand Down

0 comments on commit 8ed5852

Please sign in to comment.