Skip to content

Commit

Permalink
Merge pull request #407 from Mindgamesnl/feature/logging-interface
Browse files Browse the repository at this point in the history
Implement actual log levels
  • Loading branch information
Mindgamesnl authored Feb 13, 2024
2 parents 0a6174f + 42afebc commit 31181be
Show file tree
Hide file tree
Showing 96 changed files with 469 additions and 382 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public MapDBService() {
}

public void shutdown() {
OpenAudioLogger.toConsole("Closing database");
OpenAudioLogger.info("Closing database");
database.commit();
database.close();
databaseMap.clear();
Expand All @@ -46,7 +46,7 @@ public <T extends LegacyStore> Repository<T> getRepository(Class<T> dataClass) {
}

// create database
OpenAudioLogger.toConsole("Registering storage table for " + dataClass.getSimpleName());
OpenAudioLogger.info("Registering storage table for " + dataClass.getSimpleName());
Repository<T> createdTable = new Repository<>();
createdTable.onCreate(this, this.database, dataClass);
databaseMap.put(dataClass, createdTable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void commit() {
Class<? extends LegacyStore> dataStore = (Class<? extends LegacyStore>) Class.forName(repositoryTypeClass);
dbs.getRepository(dataStore).saveString(key, dataString);
} catch (ClassNotFoundException e) {
OpenAudioLogger.toConsole("Couldn't commit " + repositoryTypeClass + " because the class type is unknown");
OpenAudioLogger.info("Couldn't commit " + repositoryTypeClass + " because the class type is unknown");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public VistasRedisClient(Configuration configuration) {
configuration.getBoolean(StorageKey.REDIS_USE_SSL),
configuration.getString(StorageKey.REDIS_SENTINEL_MASTER_SET),
packetEvents,
"deputy_to_server"
"vistas_to_server"
);

EventApi.getInstance().registerHandler(SpigotAudioCommandEvent.class, event -> {
Expand Down Expand Up @@ -83,11 +83,11 @@ public VistasRedisClient(Configuration configuration) {
}

public void sendPacket(AbstractPacketPayload packet) {
redis.publish("server_to_deputy", OpenAudioMc.getGson().toJson(new InternalPacketWrapper(packet, null)));
redis.publish("server_to_vistas", OpenAudioMc.getGson().toJson(new InternalPacketWrapper(packet, null)));
}

public void sendPacket(AbstractPacketPayload packet, UUID serverId) {
redis.publish("server_to_deputy", OpenAudioMc.getGson().toJson(new InternalPacketWrapper(packet, serverId)));
redis.publish("server_to_vistas", OpenAudioMc.getGson().toJson(new InternalPacketWrapper(packet, serverId)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
User user = OpenAudioMc.resolveDependency(UserHooks.class).byUuid(event.getPlayer().getUniqueId());

if (user == null) {
OpenAudioLogger.toConsole("WARNING! Vistas player join user is null");
OpenAudioLogger.warn("Vistas player join user is null");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public RedisConnection(String host,
uri = builder.build();
}

OpenAudioLogger.toConsole("Connecting to redis server: " + uri.toString());
OpenAudioLogger.info("Connecting to redis server: " + uri.toString());

redisClient = RedisClient.create(uri);
redisClient.setOptions(ClientOptions.builder().autoReconnect(true).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SimpleRedisClient(String host,
this.listenerConnection = new RedisConnection(host, port, password, useSSL, sentinelMasterSet)
.connectPubSub();

// listen to packets from Spigot To Deputy
// listen to packets from Spigot To vistas
this.listenerConnection.getPubSubHandler().subscribe(channels);
this.listenerConnection.addPubSubListener(new RedisPubSubAdapter<String, String>() {
// received data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public VistasRedisServer(Configuration configuration) {
configuration.getBoolean(StorageKey.REDIS_USE_SSL),
configuration.getString(StorageKey.REDIS_SENTINEL_MASTER_SET),
packetEvents,
"server_to_deputy"
"server_to_vistas"
);

packetEvents.registerPacket(UserJoinPacket.class).setHandler(joinPacket -> {
Expand All @@ -67,7 +67,7 @@ public VistasRedisServer(Configuration configuration) {
User sender = OpenAudioMc.resolveDependency(UserHooks.class).byUuid(userExecuteAudioCommandPacket.getPlayerUuid());

if (sender == null) {
OpenAudioLogger.toConsole("User " + userExecuteAudioCommandPacket.getPlayerUuid() + " is not online, but tried to execute a command");
OpenAudioLogger.warn("User " + userExecuteAudioCommandPacket.getPlayerUuid() + " is not online, but tried to execute a command");
return;
}
authenticationDriver.activateToken(sender, userExecuteAudioCommandPacket.getArgs()[0]);
Expand Down Expand Up @@ -124,21 +124,21 @@ public VistasRedisServer(Configuration configuration) {
packetEvents.registerPacket(WrappedProxyPacket.class).setHandler(wrappedProxyPacket -> {
MinecraftServer installation = getService(ServerUserHooks.class).registerServerIfNew(wrappedProxyPacket.getServerId());
if (installation == null) {
OpenAudioLogger.toConsole("Warning! couldn't handle a packet from a server, because, well, I don't have it registered lol " + wrappedProxyPacket.getServerId());
OpenAudioLogger.warn("couldn't handle a packet from a server, because, well, I don't have it registered lol " + wrappedProxyPacket.getServerId());
return;
}

User user = OpenAudioMc.resolveDependency(UserHooks.class).byUuid(wrappedProxyPacket.getPlayerId());
if (wrappedProxyPacket.getPacket() == null) {
System.out.println("WARNING! nill packet for " + user.getName());
OpenAudioLogger.warn("nill packet for " + user.getName());
return;
}
OpenAudioMc.getService(ProxyHostService.class).onPacketReceive(user, wrappedProxyPacket.getPacket());
});
}

public void sendPacket(AbstractPacketPayload packet, UUID targetServerId) {
redis.publish("deputy_to_server", OpenAudioMc.getGson().toJson(new InternalPacketWrapper(packet, targetServerId)));
redis.publish("vistas_to_server", OpenAudioMc.getGson().toJson(new InternalPacketWrapper(packet, targetServerId)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public void startGc() {
}
}

for (VistasUser deputyUser : removeMe) {
OpenAudioLogger.toConsole("Kicking garbage connection for " + deputyUser.getName());
deputyUser.handleDefiniteDisconnect();
OpenAudioMc.getService(NetworkingService.class).remove(deputyUser.getUniqueId());
remoteUsers.remove(deputyUser.getUniqueId());
for (VistasUser vistasUser : removeMe) {
OpenAudioLogger.info("Kicking garbage connection for " + vistasUser.getName());
vistasUser.handleDefiniteDisconnect();
OpenAudioMc.getService(NetworkingService.class).remove(vistasUser.getUniqueId());
remoteUsers.remove(vistasUser.getUniqueId());
}
}, 20, 20);
}
Expand Down Expand Up @@ -124,13 +124,13 @@ public void onUserJoin(String playerName, UUID playerUuid, UUID serverId, String
MinecraftServer dpi = remoteInstallation.get(serverId);
VistasUser du = registerUserIfNew(playerUuid, playerName, ip);
du.registerInServer(serverId);
OpenAudioLogger.toConsole(playerName + " got claimed by server " + serverId.toString());
OpenAudioLogger.info(playerName + " got claimed by server " + serverId.toString());
}

public void onUserLeave(String playerName, UUID playerUuid, UUID serverId) {
MinecraftServer dpi = remoteInstallation.get(serverId);
VistasUser du = registerUserIfNew(playerUuid, playerName);
du.removeServer(serverId);
OpenAudioLogger.toConsole(playerName + " left server " + serverId.toString());
OpenAudioLogger.info(playerName + " left server " + serverId.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void removeServer(UUID s) {
}

public void handleDefiniteDisconnect() {
OpenAudioLogger.toConsole("Handling disconnect for " + getName());
OpenAudioLogger.info("Handling disconnect for " + getName());
OpenAudioMc.getService(NetworkingService.class).getClient(uuid).kickConnection();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public VistasServer() {
instance = this;
File basePath = new File(VistasConfiguration.BASE_PATH);
if (!basePath.exists()) {
OpenAudioLogger.toConsole("Creating base path");
OpenAudioLogger.info("Creating base path");
basePath.mkdir();
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public Configuration getConfigurationProvider() {

@Override
public String getPluginVersion() {
return "deputy-latest";
return "vistas-latest";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class VistasConfiguration extends Service implements Configuration {
@Inject
@SneakyThrows
public VistasConfiguration() {
OpenAudioLogger.toConsole("Using storage base path " + BASE_PATH);
OpenAudioLogger.info("Using storage base path " + BASE_PATH);
MagicValue.overWrite(MagicValue.STORAGE_DIRECTORY, new File(VistasConfiguration.BASE_PATH));
reloadConfig();
}
Expand Down Expand Up @@ -74,7 +74,7 @@ private Object resolve(String key, StorageLocation location) {
}

public void set(String key, Object value, StorageLocation location) {
OpenAudioLogger.toConsole("Setting " + key + " to " + value);
OpenAudioLogger.info("Setting " + key + " to " + value);
Map<String, Object> haystack = null;
switch (location) {
case DATA_FILE:
Expand Down Expand Up @@ -102,7 +102,7 @@ public void set(String key, Object value, StorageLocation location) {
@SneakyThrows
@Override
public void saveAll(boolean ignoreConfig) {
OpenAudioLogger.toConsole("Saving files...");
OpenAudioLogger.info("Saving files...");
DumperOptions options = new DumperOptions();
options.setPrettyFlow(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Expand Down Expand Up @@ -269,12 +269,12 @@ public void reloadConfig() {
configFile = new File(BASE_PATH + "/config.yml");

if (!dataFile.exists()) {
OpenAudioLogger.toConsole("Creating data.yml");
OpenAudioLogger.info("Creating data.yml");
dataFile = new File(FileUtil.exportResource("/data.yml", OpenAudioMc.class, new File(BASE_PATH)));
}

if (!configFile.exists()) {
OpenAudioLogger.toConsole("Creating config.yml");
OpenAudioLogger.info("Creating config.yml");
configFile = new File(FileUtil.exportResource("/config.yml", OpenAudioMc.class, new File(BASE_PATH)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public OpenAudioMc(OpenAudioInvoker invoker) throws Exception {
MagicValue.loadArguments();
if (env != null && !env.equals("")) {
SERVER_ENVIRONMENT = ServerEnvironment.valueOf(env);
OpenAudioLogger.toConsole("WARNING! STARTING IN " + env + " MODE!");
OpenAudioLogger.info("WARNING! STARTING IN " + env + " MODE!");
}

// random bullshit, go!
instance = this;
OpenAudioLogger.toConsole("Initializing build " + BUILD.getBuildNumber() + " by " + BUILD.getBuildAuthor());
OpenAudioLogger.info("Starting OpenAudioMc, build " + BUILD.getBuildNumber() + " by " + BUILD.getBuildAuthor());

// load core internal API's which are heavily used by the rest of the plugin
serviceManager.loadServices(
Expand Down Expand Up @@ -180,7 +180,7 @@ public void disable() {
serviceManager.getService(NetworkingService.class).stop();
}
} catch (NoClassDefFoundError exception) {
OpenAudioLogger.toConsole("Bukkit already unloaded the OA+ classes, can't kill tokens.");
OpenAudioLogger.warn("Core dependencies were already unloaded by the classloader, skipping shutdown");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public <T extends AudioEvent> HandlerHolder<T> on(Class<T> eventType) {
String methodThatInvoked = e.getMethodName();
String classThatInvoked = e.getClassName();
int lineThatInvoked = e.getLineNumber();
OpenAudioLogger.toConsole("Deprecated event listener registration, please use the new event system. Invoked from " + classThatInvoked + "#" + methodThatInvoked + ":" + lineThatInvoked);
OpenAudioLogger.warn("Deprecated event listener registration, please use the new event system. Invoked from " + classThatInvoked + "#" + methodThatInvoked + ":" + lineThatInvoked);

// check if this event is supported here
EventSupport support = getEventSupportFor(eventType);
Expand Down Expand Up @@ -124,9 +124,7 @@ public <T extends AudioEvent> T fire(T event) {
try {
subscriber.call(event);
} catch (Exception e) {
OpenAudioLogger.handleException(e);
OpenAudioLogger.toConsole("Failed to handle an event handler");
e.printStackTrace();
OpenAudioLogger.error(e, "Failed to handle an event (" + event.getClass().getSimpleName() + ") handler in " + subscriber.getHandler().getClass().getName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public abstract class ExternalModule {
public abstract void on(ModuleEvent event);

protected void log(String message) {
OpenAudioLogger.toConsole("[module-" + getName() + "] " + message);
OpenAudioLogger.info("[module-" + getName() + "] " + message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ public void onEnable() {

// timing end and calc
Instant finish = Instant.now();
OpenAudioLogger.toConsole("Starting and loading took " + Duration.between(boot, finish).toMillis() + "MS");
OpenAudioLogger.info("Starting and loading took " + Duration.between(boot, finish).toMillis() + "MS");
OpenAudioMc.getInstance().postBoot();
} catch (Exception e) {
OpenAudioLogger.handleException(e);
e.printStackTrace();
OpenAudioLogger.error(e, "Failed to boot OpenAudioMc, please report this stacktrace");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public BungeeConfiguration() {
dataConfig = getFile("data.yml");
mainConfig = getFile("config.yml");

OpenAudioLogger.toConsole("Starting configuration module");
OpenAudioLogger.info("Starting configuration module");
this.loadSettings();
}

Expand Down Expand Up @@ -266,8 +266,7 @@ public void saveAll(boolean includeConfig) {
}
ConfigurationProvider.getProvider(YamlConfiguration.class).save(dataConfig, new File(OpenAudioMcBungee.getInstance().getDataFolder(), "data.yml"));
} catch (IOException e) {
OpenAudioLogger.handleException(e);
e.printStackTrace();
OpenAudioLogger.error(e, "Failed to save config/data");
}
}

Expand All @@ -294,8 +293,7 @@ private net.md_5.bungee.config.Configuration getFile(String filename) {
try {
load = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(OpenAudioMcBungee.getInstance().getDataFolder(), filename));
} catch (IOException e) {
OpenAudioLogger.handleException(e);
e.printStackTrace();
OpenAudioLogger.error(e, "Could not load file: " + filename);
}
return load;
}
Expand All @@ -310,17 +308,15 @@ private void saveDefaultFile(String filename, boolean hard) {
try {
Files.delete(file.toPath());
} catch (IOException e) {
OpenAudioLogger.handleException(e);
e.printStackTrace();
OpenAudioLogger.error(e, "Could not delete file: " + filename);
}
}

if (!file.exists() || hard) {
try (InputStream in = OpenAudioMcBungee.getInstance().getResourceAsStream(filename)) {
Files.copy(in, file.toPath());
} catch (IOException e) {
OpenAudioLogger.handleException(e);
e.printStackTrace();
OpenAudioLogger.error(e, "Could not save default file: " + filename);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ public class PlayerConnectionListener implements Listener {

@EventHandler
public void onPostLogin(PostLoginEvent event) {
OpenAudioLogger.toConsole("Post login for " + event.getPlayer().getName());

if (!BungeeUtils.areEncodersReady(event.getPlayer())) {
OpenAudioLogger.toConsole("Player " + event.getPlayer().getName() + " is not ready yet during postLogin, waiting for next event");
OpenAudioLogger.warn("Player " + event.getPlayer().getName() + " is not ready yet during postLogin, waiting for next event");
return;
}

Expand All @@ -56,26 +54,26 @@ public void onConnect(ServerConnectedEvent event) {
));

if (!BungeeUtils.areEncodersReady(event.getPlayer())) {
OpenAudioLogger.toConsole("Player " + event.getPlayer().getName() + " is not ready yet during connectEvent, waiting for next event");
OpenAudioLogger.warn("Player " + event.getPlayer().getName() + " is not ready yet during connectEvent, waiting for next event");
return;
}

// possibly polyfill the missing client
if (!OpenAudioMc.getService(NetworkingService.class).hasClient(event.getPlayer().getUniqueId())) {
OpenAudioLogger.toConsole("Player " + event.getPlayer().getName() + "is not registered yet, forcing login during connect");
OpenAudioLogger.warn("Player " + event.getPlayer().getName() + "is not registered yet, forcing login during connect");
OpenAudioMc.getService(NetworkingService.class).register(new BungeeUserAdapter(event.getPlayer()), null);
}
}

@EventHandler
public void onSwitch(ServerSwitchEvent event) {
if (!BungeeUtils.areEncodersReady(event.getPlayer())) {
OpenAudioLogger.toConsole("Player " + event.getPlayer().getName() + " is not ready yet during serverSwitch, waiting for next event");
OpenAudioLogger.warn("Player " + event.getPlayer().getName() + " is not ready yet during serverSwitch, waiting for next event");
}

// did we have to skip the login packet?
if (!OpenAudioMc.getService(NetworkingService.class).hasClient(event.getPlayer().getUniqueId())) {
OpenAudioLogger.toConsole("Player " + event.getPlayer().getName() + " is not registered yet, forcing login during switch");
OpenAudioLogger.warn("Player " + event.getPlayer().getName() + " is not registered yet, forcing login during switch");
OpenAudioMc.getService(NetworkingService.class).register(new BungeeUserAdapter(event.getPlayer()), null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private List<ProxiedPlayer> getPlayers(CommandSender commandSender) {
if (proxiedPlayer != null) players.add(proxiedPlayer);
} else {
//you fucked it
OpenAudioLogger.toConsole("Invalid player query. Try something like @a, @a[server=lobby], username or other arguments.");
OpenAudioLogger.warn("Invalid player query. Try something like @a, @a[server=lobby], username or other arguments.");
commandSender.sendMessage("Invalid player query. Try something like @a, @a[server=lobby], username or other arguments.");
}
return players;
Expand Down
Loading

0 comments on commit 31181be

Please sign in to comment.