Skip to content

Commit 8bad2c4

Browse files
2008Chococerealcable
authored andcommitted
Use plugin logger instead of Minecraft logger in README example
The JavaPlugin class provides plugins with their own logger via getLogger() which is the preferred means of logging content to the console as it prepends the plugin's name. Using a Logger with the Minecraft prefix is non-descript and poor practice because it will not properly source from where the log message is coming. Beginners should not be given this poor practice as an example.
1 parent 9520d88 commit 8bad2c4

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

README.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ Implementing Vault is quite simple. It requires getting the Economy, Permission,
6767
```java
6868
package com.example.plugin;
6969

70-
import java.util.logging.Logger;
71-
7270
import net.milkbowl.vault.chat.Chat;
7371
import net.milkbowl.vault.economy.Economy;
7472
import net.milkbowl.vault.economy.EconomyResponse;
@@ -82,20 +80,19 @@ import org.bukkit.plugin.java.JavaPlugin;
8280

8381
public class ExamplePlugin extends JavaPlugin {
8482

85-
private static final Logger log = Logger.getLogger("Minecraft");
8683
private static Economy econ = null;
8784
private static Permission perms = null;
8885
private static Chat chat = null;
8986

9087
@Override
9188
public void onDisable() {
92-
log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
89+
getLogger().info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
9390
}
9491

9592
@Override
9693
public void onEnable() {
9794
if (!setupEconomy() ) {
98-
log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
95+
getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
9996
getServer().getPluginManager().disablePlugin(this);
10097
return;
10198
}
@@ -129,7 +126,7 @@ public class ExamplePlugin extends JavaPlugin {
129126

130127
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
131128
if(!(sender instanceof Player)) {
132-
log.info("Only players are supported for this Example Plugin, but you should not do this!!!");
129+
getLogger().info("Only players are supported for this Example Plugin, but you should not do this!!!");
133130
return true;
134131
}
135132

0 commit comments

Comments
 (0)