Skip to content

Commit

Permalink
TS-31571 Daemonzie logging
Browse files Browse the repository at this point in the history
  • Loading branch information
stahlbauer committed Jul 31, 2024
1 parent 4e1925c commit 9bcd624
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ public class LogToTeamscaleAppender extends AppenderBase<ILoggingEvent> {
private int batchSize = 10;
private Duration flushInterval = Duration.ofSeconds(3);
private final List<ProfilerLogEntry> logBuffer = new ArrayList<>();
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private final ScheduledExecutorService scheduler;

public LogToTeamscaleAppender() {
this.scheduler = Executors.newScheduledThreadPool(1, r -> {
// Make the thread a daemon so that it does not prevent the JVM from terminating.
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
return t;
});
}

public void setTeamscaleClient(TeamscaleClient teamscaleClient) {
this.teamscaleClient = teamscaleClient;
Expand Down Expand Up @@ -114,5 +123,4 @@ public static void addTeamscaleAppenderTo(LoggerContext context, AgentOptions ag
rootLogger.addAppender(logToTeamscaleAppender);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public void systemTestRetrieveConfig() throws Exception {

teamscaleMockServer.shutdown();

assertThat(teamscaleMockServer.getProfilerEvents()).containsExactly(
"Profiler registered and requested configuration my-config", "Profiler 123 sent heartbeat",
assertThat(teamscaleMockServer.getProfilerEvents()).as("We expect a sequence of interactions with the mock. " +
"Note that unexpected interactions can be caused by old agent instances that have not been killed properly.") //
.containsExactly("Profiler registered and requested configuration my-config", "Profiler 123 sent heartbeat",
"Profiler 123 unregistered");
}

Expand Down

0 comments on commit 9bcd624

Please sign in to comment.