Skip to content

Commit

Permalink
Development: Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
krusche committed Dec 3, 2024
1 parent 05646bf commit 1b9e7f8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package de.tum.cit.aet.artemis.core.config;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;

/**
* A custom Logback filter to suppress specific log messages from the
* StompBrokerRelayMessageHandler in a Spring Boot application.
*
* <p>
* This filter identifies log messages containing the error:
* "Did not receive data from ... within the 60000ms connection TTL. The connection will now be closed."
* and suppresses them while allowing other log messages to pass through.
*
* <p>
* The purpose of this filter is to reduce noise in the logs by eliminating
* repetitive or irrelevant error messages caused by client disconnections.
*/
public class StompErrorLogFilter extends Filter<ILoggingEvent> {

/**
* Decides whether a log message should be suppressed or passed through.
*
* <p>
* This method checks if the log message originates from the
* StompBrokerRelayMessageHandler logger and contains the specific error message
* about the 60000ms connection TTL timeout. If both conditions are met,
* the log message is suppressed (denied). All other log messages are allowed.
*
* @param event the logging event containing the log message and metadata
* @return {@code FilterReply.DENY} if the message matches the specific error to suppress,
* otherwise {@code FilterReply.NEUTRAL} to allow the message through.
*/
@Override
public FilterReply decide(ILoggingEvent event) {
String loggerName = event.getLoggerName();
String message = event.getFormattedMessage();

// Check if the logger and message match the specific error to suppress
if ("org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler".equals(loggerName) && message.contains("Did not receive data from")
&& message.contains("connection TTL. The connection will now be closed.")) {
return FilterReply.DENY; // Suppress this specific log message
}

return FilterReply.NEUTRAL; // Allow other messages
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,17 @@ private boolean authenticateUser(UserSshPublicKey storedKey, PublicKey providedK
* @return true if the authentication succeeds, and false if it doesn't
*/
private boolean authenticateBuildAgent(PublicKey providedKey, ServerSession session) {
if (localCIBuildJobQueueService.isPresent()
&& localCIBuildJobQueueService.get().getBuildAgentInformation().stream().anyMatch(agent -> checkPublicKeyMatchesBuildAgentPublicKey(agent, providedKey))) {

log.info("Authenticating as build agent");
session.setAttribute(SshConstants.IS_BUILD_AGENT_KEY, true);
return true;
if (localCIBuildJobQueueService.isPresent()) {
// Find the build agent that matches the provided key
Optional<BuildAgentInformation> matchingAgent = localCIBuildJobQueueService.get().getBuildAgentInformation().stream()
.filter(agent -> checkPublicKeyMatchesBuildAgentPublicKey(agent, providedKey)).findFirst();

if (matchingAgent.isPresent()) {
var agent = matchingAgent.get().buildAgent();
log.info("Authenticating build agent {} on address {}", agent.displayName(), agent.memberAddress());
session.setAttribute(SshConstants.IS_BUILD_AGENT_KEY, true);
return true;
}
}
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />

<!-- Add the custom filter -->
<turboFilter class="de.tum.cit.aet.artemis.core.config.StompErrorLogFilter" />

<!-- The FILE and ASYNC appenders are here as examples for a production configuration -->
<!--
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
Expand Down

0 comments on commit 1b9e7f8

Please sign in to comment.