Skip to content

Commit

Permalink
Add log line limit
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Jul 19, 2024
1 parent 70dc3f0 commit dfef4f2
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions bootstrap/manager/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ USER app:app

WORKDIR /opt/app/config

VOLUME /opt/app/config/logs

COPY bootstrap/manager/build/libs/MCXboxBroadcastManager.jar /opt/app/MCXboxBroadcastManager.jar

CMD ["java", "-jar", "/opt/app/MCXboxBroadcastManager.jar"]
1 change: 1 addition & 0 deletions bootstrap/manager/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {

api(project(":core"))
api(libs.bedrock.common)
api(libs.guava)
}

tasks.withType<Test> {
Expand Down
3 changes: 2 additions & 1 deletion bootstrap/manager/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ services:
ports:
- "8082:8082"
volumes:
- /path/to/config/:/opt/app/config/
- /path/to/application.yaml:/opt/app/config/application.yaml
- /path/to/logs/:/opt/app/config/logs/
depends_on:
- mongo
environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public record MainConfig (
boolean auth,
UpdateTime updateTime,
@Min(1)
int workerThreads
int workerThreads,
@Min(1)
int logSize
) {
@ConstructorBinding
public MainConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public Map<String, String> settings(HttpServletResponse response) {
MainConfig config = backendManager.config();

return Map.of(
"Authentication", String.valueOf(config.auth()),
"Authentication", config.auth() ? "Enabled" : "Disabled",
"Update time (s)", "Server: " + config.updateTime().server() + ", Session: " + config.updateTime().session() + ", Stats: " + config.updateTime().stats() + ", Friend: " + config.updateTime().friend(),
"Worker Threads", String.valueOf(config.workerThreads())
"Worker Threads", String.valueOf(config.workerThreads()),
"Log lines", String.valueOf(config.logSize())
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rtm516.mcxboxbroadcast.manager.models;

import com.google.common.collect.EvictingQueue;
import com.rtm516.mcxboxbroadcast.core.FriendManager;
import com.rtm516.mcxboxbroadcast.core.SessionManager;
import com.rtm516.mcxboxbroadcast.core.configs.FriendSyncConfig;
Expand All @@ -18,7 +19,7 @@

public class BotContainer {
private final Bot bot;
private final StringBuilder logs = new StringBuilder();
private final EvictingQueue<String> logQueue;
private final DateTimeFormatter logTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
private final BotManager botManager;
private final StorageManager storageManager;
Expand All @@ -32,6 +33,7 @@ public BotContainer(BotManager botManager, Bot bot) {
this.botManager = botManager;
this.bot = bot;
this.storageManager = new MongoStorageManager(this);
this.logQueue = EvictingQueue.create(botManager.backendManager().config().logSize());

status = Status.OFFLINE;
}
Expand All @@ -54,7 +56,7 @@ public Bot bot() {
* @return the bot logs
*/
public String logs() {
return logs.toString();
return String.join("\n", logQueue);
}

/**
Expand All @@ -64,7 +66,7 @@ public String logs() {
* @param message the message
*/
protected void log(String level, String message) {
logs.append("[" + LocalDateTime.now().format(logTimeFormatter) + " " + level + "]").append(message).append("\n");
logQueue.add("[" + LocalDateTime.now().format(logTimeFormatter) + " " + level + "]" + message);
}

/**
Expand Down
1 change: 1 addition & 0 deletions bootstrap/manager/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ mcxb:
stats: 120
friend: 20
worker-threads: 6
log-size: 1024
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spring = "3.3.0"
spring-security-test = "6.3.1"
junit = "1.10.2"
spring-dependency = "1.1.5" # Spring Dependency Management Plugin
guava = "33.2.1-jre"

shadow = "8.1.1"
indra = "3.1.3"
Expand Down Expand Up @@ -62,6 +63,8 @@ spring-security-test = { group = "org.springframework.security", name = "spring-

junit-platform-launcher = { group = "org.junit.platform", name = "junit-platform-launcher", version.ref = "junit" }

guava = { group = "com.google.guava", name = "guava", version.ref = "guava" }

[bundles]
jackson = [
"jackson-core",
Expand Down

0 comments on commit dfef4f2

Please sign in to comment.