seq logging

This commit is contained in:
LionTion committed 2026-10-30 08:54:03 +01:00
1 parent 5bd9170800
commit fb37ba3b50
3 files changed
+56 -8

No files matched your search

+12 -1
View File
@@ -10,7 +10,7 @@
</parent> </parent>
<groupId>de.exodus-hn</groupId> <groupId>de.exodus-hn</groupId>
<artifactId>excalibur-tour</artifactId> <artifactId>excalibur-tour</artifactId>
<version>0.1.0</version> <version>0.1.1</version>
<name/> <name/>
<description/> <description/>
<url/> <url/>
@@ -29,6 +29,12 @@
<properties> <properties>
<java.version>26</java.version> <java.version>26</java.version>
</properties> </properties>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@@ -102,6 +108,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId> <artifactId>spring-boot-starter-websocket</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.github.serilogj</groupId>
<artifactId>serilogj</artifactId>
<version>0.6.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
@@ -3,13 +3,13 @@ package de.exodus_hn.excalibur_tour.configurations;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.paho.client.mqttv3.*; import org.eclipse.paho.client.mqttv3.*;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler; import org.springframework.web.socket.handler.TextWebSocketHandler;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy; import jakarta.annotation.PreDestroy;
import java.io.IOException; import java.io.IOException;
@@ -42,6 +42,13 @@ public class MqttConfig extends TextWebSocketHandler {
@Value("${testing.isMqttDev}") @Value("${testing.isMqttDev}")
public boolean isDev; public boolean isDev;
private final serilogj.core.Logger seqLogger;
@Autowired
public MqttConfig(serilogj.core.Logger seqLogger) {
this.seqLogger = seqLogger;
}
@PostConstruct @PostConstruct
public void initMqtt() { public void initMqtt() {
try { try {
@@ -78,10 +85,10 @@ public class MqttConfig extends TextWebSocketHandler {
if (topic.equals(eventTopic)) { if (topic.equals(eventTopic)) {
if ("online".equalsIgnoreCase(payload)) { if ("online".equalsIgnoreCase(payload)) {
swordIsOnline.set(true); swordIsOnline.set(true);
logger.info("sword is online"); seqLogger.information("[{Service}]: Got Sword {State}!", (isDev ? "Staging-" : "") + "Backend", "Online");
} else if ("offline".equalsIgnoreCase(payload)) { } else if ("offline".equalsIgnoreCase(payload)) {
swordIsOnline.set(false); swordIsOnline.set(false);
logger.info("sword is offline"); seqLogger.information("[{Service}]: Got Sword {State}!", (isDev ? "Staging-" : "") + "Backend", "Offline");
} }
} }
@@ -136,16 +143,16 @@ public class MqttConfig extends TextWebSocketHandler {
if (clientMsg.payload.equals("takeLock")) { if (clientMsg.payload.equals("takeLock")) {
logger.info(String.format("SID: %s LID: %s", session.getId(), swordLockId.get())); logger.info(String.format("SID: %s LID: %s", session.getId(), swordLockId.get()));
if (swordLock.compareAndSet(false, true)) { if (swordLock.compareAndSet(false, true)) {
logger.info("LOCK SET");
swordLockId.set(session.getId()); swordLockId.set(session.getId());
broadcastToWebSockets("system/swordLock", "locked"); broadcastToWebSockets("system/swordLock", "locked");
seqLogger.information("[{Service}]: SwordMutexLock {LockState}", (isDev ? "Staging-" : "") + "Backend", "Locked");
} }
} else if (clientMsg.payload.equals("giveLock")) { } else if (clientMsg.payload.equals("giveLock")) {
logger.info(String.format("SID: %s LID: %s", session.getId(), swordLockId.get())); logger.info(String.format("SID: %s LID: %s", session.getId(), swordLockId.get()));
if (session.getId().equals(swordLockId.get())) { if (session.getId().equals(swordLockId.get())) {
logger.info("LOCK UNSET");
swordLock.set(false); swordLock.set(false);
broadcastToWebSockets("system/swordLock", "unlocked"); broadcastToWebSockets("system/swordLock", "unlocked");
seqLogger.information("[{Service}]: SwordMutexLock {LockState}", (isDev ? "Staging-" : "") + "Backend", "Unlocked");
} }
} }
} }
@@ -169,8 +176,8 @@ public class MqttConfig extends TextWebSocketHandler {
if (swordlockid != null && swordlockid.equals(sessionId)) { if (swordlockid != null && swordlockid.equals(sessionId)) {
swordLock.set(false); swordLock.set(false);
swordLockId.set(null); swordLockId.set(null);
logger.info("LOCK UNSET");
broadcastToWebSockets("system/swordLock", "unlocked"); broadcastToWebSockets("system/swordLock", "unlocked");
seqLogger.information("[{Service}]: SwordMutexLock {LockState} due to client disconnect", (isDev ? "Staging-" : "") + "Backend", "Unlocked");
} }
logger.fine("Client getrennt: " + session.getId()); logger.fine("Client getrennt: " + session.getId());
@@ -185,8 +192,8 @@ public class MqttConfig extends TextWebSocketHandler {
if (swordlockid != null && swordlockid.equals(sessionId)) { if (swordlockid != null && swordlockid.equals(sessionId)) {
swordLock.set(false); swordLock.set(false);
swordLockId.set(null); swordLockId.set(null);
logger.info("LOCK UNSET");
broadcastToWebSockets("system/swordLock", "unlocked"); broadcastToWebSockets("system/swordLock", "unlocked");
seqLogger.information("[{Service}]: SwordMutexLock {LockState} due to client error", (isDev ? "Staging-" : "") + "Backend", "Unlocked");
} }
} }
@@ -0,0 +1,30 @@
package de.exodus_hn.excalibur_tour.configurations;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import serilogj.LoggerConfiguration;
import serilogj.events.LogEventLevel;
import static serilogj.sinks.coloredconsole.ColoredConsoleSinkConfigurator.coloredConsole;
import static serilogj.sinks.seq.SeqSinkConfigurator.seq;
@Configuration
public class SerilogjConfig {
@Value("${seq.server.url}")
private String seqUrl;
@Value("${seq.server.apiKey}")
private String seqApiKey;
@Bean
public serilogj.core.Logger seqLogger() {
return new LoggerConfiguration()
.writeTo(coloredConsole())
.writeTo(seq(seqUrl, seqApiKey))
.setMinimumLevel(LogEventLevel.Verbose)
.createLogger();
}
}