Logging System
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
package org.yuemi.yuelicenser;
|
package org.yuemi.feather;
|
||||||
|
|
||||||
// Bukkit
|
// Bukkit
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -9,21 +9,22 @@ import org.bukkit.event.EventHandler;
|
|||||||
// PlaceholderAPI
|
// PlaceholderAPI
|
||||||
//import me.clip.placeholderapi.PlaceholderAPI;
|
//import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
//import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
//import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
|
// YueMi
|
||||||
|
import org.yuemi.feather.functions.LoggerUtil;
|
||||||
|
|
||||||
public class Main extends JavaPlugin {
|
public class Main extends JavaPlugin {
|
||||||
public enum LogType {
|
String pluginName = getDescription().getName();
|
||||||
NONE, LOW, MEDIUM, HIGH
|
|
||||||
}
|
|
||||||
private LogType logType = LogType.LOW;
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Save the default config if it doesn't exist yet
|
saveDefaultConfig(); // Save the default config if it doesn't exist yet
|
||||||
saveDefaultConfig();
|
LoggerUtil.logs(1, "Enabling " + pluginName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Implement Here
|
LoggerUtil.logs(1, "Disabling " + pluginName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
45
src/main/java/org/yuemi/feather/functions/LoggerUtil.java
Normal file
45
src/main/java/org/yuemi/feather/functions/LoggerUtil.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package org.yuemi.feather.functions;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple logger with numeric level input
|
||||||
|
*/
|
||||||
|
public class LoggerUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log message with numeric level:
|
||||||
|
* 1 = INFO, 2 = WARNING, 3 = ERROR, 4 = DEBUG
|
||||||
|
*/
|
||||||
|
public static void logs(int level, Object message) {
|
||||||
|
String msg = message.toString();
|
||||||
|
|
||||||
|
String prefix = "[FeatherUtils]";
|
||||||
|
String formattedMessage;
|
||||||
|
|
||||||
|
switch (level) {
|
||||||
|
case 1: // INFO
|
||||||
|
formattedMessage = String.format("%s %s%s", prefix, ChatColor.GREEN, msg);
|
||||||
|
Bukkit.getLogger().info(formattedMessage);
|
||||||
|
break;
|
||||||
|
case 2: // WARNING
|
||||||
|
formattedMessage = String.format("%s %s%s", prefix, ChatColor.YELLOW, msg);
|
||||||
|
Bukkit.getLogger().warning(formattedMessage);
|
||||||
|
break;
|
||||||
|
case 3: // ERROR
|
||||||
|
formattedMessage = String.format("%s %s%s", prefix, ChatColor.RED, msg);
|
||||||
|
Bukkit.getLogger().severe(formattedMessage);
|
||||||
|
break;
|
||||||
|
case 4: // DEBUG
|
||||||
|
formattedMessage = String.format("%s %s%s", prefix, ChatColor.GRAY, msg);
|
||||||
|
Bukkit.getLogger().info(formattedMessage);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// fallback to info if level wrong
|
||||||
|
formattedMessage = String.format("%s %s%s", prefix, ChatColor.GREEN, msg);
|
||||||
|
Bukkit.getLogger().info(formattedMessage);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user