Skip to content

Commit b245920

Browse files
Use default logger instead of making new one
1 parent 251bc5d commit b245920

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/main/java/dev/railroadide/discordplugin/DiscordPlugin.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import dev.railroadide.discordplugin.activity.DiscordActivity;
1212
import dev.railroadide.discordplugin.core.DiscordCore;
1313
import dev.railroadide.logger.Logger;
14-
import dev.railroadide.logger.LoggerManager;
1514
import dev.railroadide.railroadpluginapi.Plugin;
1615
import dev.railroadide.railroadpluginapi.PluginContext;
1716
import dev.railroadide.railroadpluginapi.Registries;
@@ -23,6 +22,7 @@
2322
import dev.railroadide.railroadpluginapi.events.ProjectEvent;
2423
import dev.railroadide.railroadpluginapi.services.ApplicationInfoService;
2524
import dev.railroadide.railroadpluginapi.services.IDEStateService;
25+
import lombok.Getter;
2626

2727
import java.nio.file.Files;
2828

@@ -32,7 +32,8 @@ public class DiscordPlugin implements Plugin {
3232
.disableHtmlEscaping()
3333
.create();
3434

35-
public static final Logger LOGGER = LoggerManager.create(DiscordPlugin.class).build();
35+
@Getter
36+
public static Logger logger;
3637

3738
private DiscordCore discordCore;
3839

@@ -50,7 +51,7 @@ public void onEnable(PluginContext context) {
5051
.defaultValue(853387211897700394L) // Default client ID for Railroad Discord
5152
.build());
5253

53-
context.setLogger(LOGGER);
54+
logger = context.getLogger();
5455

5556
EventBus eventBus = context.getEventBus();
5657
LocalizationService localizationService = LocalizationServiceLocator.getInstance();
@@ -61,13 +62,13 @@ public void onEnable(PluginContext context) {
6162
if (event.isOpened()) {
6263
ApplicationInfoService applicationInfo = context.getService(ApplicationInfoService.class);
6364
if (applicationInfo == null) {
64-
LOGGER.warn("ApplicationInfoService is not available, cannot update Discord activity.");
65+
logger.warn("ApplicationInfoService is not available, cannot update Discord activity.");
6566
return;
6667
}
6768

6869
Project project = event.project();
6970
if (project == null) {
70-
LOGGER.warn("Project is null, cannot update Discord activity.");
71+
logger.warn("Project is null, cannot update Discord activity.");
7172
return;
7273
}
7374

@@ -90,13 +91,13 @@ public void onEnable(PluginContext context) {
9091
if (event.isActivated()) {
9192
ApplicationInfoService applicationInfo = context.getService(ApplicationInfoService.class);
9293
if (applicationInfo == null) {
93-
LOGGER.warn("ApplicationInfoService is not available, cannot update Discord activity.");
94+
logger.warn("ApplicationInfoService is not available, cannot update Discord activity.");
9495
return;
9596
}
9697

9798
IDEStateService ideState = context.getService(IDEStateService.class);
9899
if (ideState == null) {
99-
LOGGER.warn("IDEStateService is not available, cannot update Discord activity.");
100+
logger.warn("IDEStateService is not available, cannot update Discord activity.");
100101
return;
101102
}
102103

@@ -124,7 +125,7 @@ public void onEnable(PluginContext context) {
124125
if (discordCore != null) {
125126
ApplicationInfoService applicationInfo = context.getService(ApplicationInfoService.class);
126127
if (applicationInfo == null) {
127-
LOGGER.warn("ApplicationInfoService is not available, cannot update Discord activity.");
128+
logger.warn("ApplicationInfoService is not available, cannot update Discord activity.");
128129
return;
129130
}
130131

@@ -142,7 +143,7 @@ public void onEnable(PluginContext context) {
142143
discordCore = new DiscordCore(String.valueOf(discordId.getValue()));
143144
discordCore.start();
144145

145-
LOGGER.info("Discord integration started successfully with client ID: " + discordId.getValue());
146+
logger.info("Discord integration started successfully with client ID: " + discordId.getValue());
146147

147148
DiscordActivity.builder()
148149
.playing()
@@ -158,7 +159,7 @@ public void onEnable(PluginContext context) {
158159
}
159160
});
160161
} catch (Exception exception) {
161-
LOGGER.error("Failed to start Discord integration", exception);
162+
logger.error("Failed to start Discord integration", exception);
162163
discordCore = null;
163164
}
164165
}

src/main/java/dev/railroadide/discordplugin/core/DiscordCore.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private void runCallbacks() {
113113

114114
private void handleCommand(DiscordCommand command) {
115115
if (command.isError()) {
116-
DiscordPlugin.LOGGER.error("Received error from Discord IPC channel: {}", command);
116+
DiscordPlugin.getLogger().error("Received error from Discord IPC channel: {}", command);
117117
return;
118118
}
119119

@@ -169,7 +169,7 @@ private void sendString(String string) throws IOException {
169169
public void onReady() {
170170
this.connectionState = DiscordConnectionState.CONNECTED;
171171
registerEvents();
172-
DiscordPlugin.LOGGER.info("Discord IPC channel is ready");
172+
DiscordPlugin.getLogger().info("Discord IPC channel is ready");
173173

174174
while (!this.commandQueue.isEmpty()) {
175175
CommandWithCallback commandWithCallback = this.commandQueue.poll();
@@ -189,7 +189,7 @@ private void registerEvents() {
189189
command.setEvt(event);
190190
command.setArgs(DiscordPlugin.GSON.toJsonTree(eventHandler.getRegistrationArgs()));
191191
command.setNonce(Long.toString(++this.nonce));
192-
sendCommand(command, response -> DiscordPlugin.LOGGER.debug("Registered event {}", event.name()));
192+
sendCommand(command, response -> DiscordPlugin.getLogger().debug("Registered event {}", event.name()));
193193
}
194194
}
195195

@@ -211,7 +211,7 @@ private void sendCommand(DiscordCommand command, Consumer<DiscordCommand> callba
211211
public DiscordResult checkError(DiscordCommand command) {
212212
if (command.getEvt() == DiscordCommand.Event.ERROR) {
213213
var error = DiscordPlugin.GSON.fromJson(command.getData(), DiscordError.class);
214-
DiscordPlugin.LOGGER.error("Received error from Discord IPC channel: {}", error.getMessage());
214+
DiscordPlugin.getLogger().error("Received error from Discord IPC channel: {}", error.getMessage());
215215

216216
return DiscordResult.fromCode(error.getCode());
217217
}

0 commit comments

Comments
 (0)