Skip to content

Commit

Permalink
[WFLY-7132] Improve logging of exceptions during embedded process exit
Browse files Browse the repository at this point in the history
  • Loading branch information
bstansberry committed Jan 20, 2025
1 parent bb00e4a commit 7b89469
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ private void exit() {
} catch (RuntimeException rte) {
throw rte;
} catch (InterruptedException ite) {
EmbeddedLogger.ROOT_LOGGER.error(ite.getLocalizedMessage(), ite);
logExitError(ite);
Thread.currentThread().interrupt();
} catch (Exception ex) {
EmbeddedLogger.ROOT_LOGGER.error(ex.getLocalizedMessage(), ex);
logExitError(ex);
}

embeddedProcess.getProcessStateNotifier().removeProcessStateListener(processStateListener);
Expand All @@ -196,10 +196,10 @@ private void exit() {
} catch (RuntimeException rte) {
throw rte;
} catch (InterruptedException ite) {
EmbeddedLogger.ROOT_LOGGER.error(ite.getLocalizedMessage(), ite);
logExitError(ite);
Thread.currentThread().interrupt();
} catch (Exception ex) {
EmbeddedLogger.ROOT_LOGGER.error(ex.getLocalizedMessage(), ex);
logExitError(ex);
}
}

Expand All @@ -209,4 +209,8 @@ private void exit() {
embeddedProcess = null;
}
}

private void logExitError(Exception ex) {
EmbeddedLogger.ROOT_LOGGER.errorExitingEmbeddedProcess(ex, type.getLogForm(), ex.getLocalizedMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,8 @@ public interface EmbeddedLogger extends BasicLogger {
@Message(id = 146, value = "Failed to restore context %s")
@LogMessage(level = Logger.Level.ERROR)
void failedToRestoreContext(@Cause Throwable cause, Context context);

@Message(id = 147, value = "Error exiting embedded %s: %s")
@LogMessage(level = Logger.Level.ERROR)
void errorExitingEmbeddedProcess(@Cause Throwable cause, String processType, String error);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package org.wildfly.core.embedded.spi;

import java.util.Locale;

/**
* Service interface that standalone server or host controller bootstrap logic can implement
* to allow their type of process to be bootstrapped in an embedded environment.
Expand All @@ -13,7 +15,11 @@ public interface EmbeddedProcessBootstrap {

enum Type {
STANDALONE_SERVER,
HOST_CONTROLLER
HOST_CONTROLLER;

public String getLogForm() {
return name().toLowerCase(Locale.ENGLISH).replace("_", " ");
}
}

/**
Expand Down

0 comments on commit 7b89469

Please sign in to comment.