Skip to content

Commit 173a6c4

Browse files
committed
Another attempt at closing log handlers before exit, this time not relying on channel events
1 parent 6aafeb3 commit 173a6c4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/java/com/cloudbees/jenkins/support/SupportPlugin.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,15 @@ public Void call() {
862862
// avoid double installation of the handler. JNLP agents can reconnect to the controller multiple times
863863
// and each connection gets a different RemoteClassLoader, so we need to evict them by class name,
864864
// not by their identity.
865+
closeAll();
866+
Runtime.getRuntime().addShutdownHook(new Thread(LogInitializer::closeAll, "close log handlers"));
867+
LogHolder.AGENT_LOG_HANDLER.setLevel(level);
868+
LogHolder.AGENT_LOG_HANDLER.setDirectory(new File(rootPath.getRemote(), SUPPORT_DIRECTORY_NAME), "all");
869+
ROOT_LOGGER.addHandler(LogHolder.AGENT_LOG_HANDLER);
870+
return null;
871+
}
872+
873+
private static void closeAll() {
865874
for (Handler h : ROOT_LOGGER.getHandlers()) {
866875
if (h.getClass()
867876
.getName()
@@ -874,10 +883,6 @@ public Void call() {
874883
}
875884
}
876885
}
877-
LogHolder.AGENT_LOG_HANDLER.setLevel(level);
878-
LogHolder.AGENT_LOG_HANDLER.setDirectory(new File(rootPath.getRemote(), SUPPORT_DIRECTORY_NAME), "all");
879-
ROOT_LOGGER.addHandler(LogHolder.AGENT_LOG_HANDLER);
880-
return null;
881886
}
882887
}
883888

0 commit comments

Comments
 (0)