Skip to content

Commit

Permalink
Use proper logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
drtshock committed May 2, 2013
1 parent fa7d89a commit f326d0a
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Essentials/src/net/ess3/I18n.java
Expand Up @@ -126,7 +126,7 @@ public void updateLocale(final String loc)
currentLocale = new Locale(parts[0], parts[1], parts[2]);
}
ResourceBundle.clearCache();
Logger.getLogger("Minecraft").log(Level.INFO, String.format("Using locale %s", currentLocale.toString()));
ess.getLogger().log(Level.INFO, String.format("Using locale %s", currentLocale.toString()));
customBundle = ResourceBundle.getBundle(MESSAGES, currentLocale, new FileResClassLoader(I18n.class.getClassLoader(), ess));
localeBundle = ResourceBundle.getBundle(MESSAGES, currentLocale);
}
Expand Down
13 changes: 6 additions & 7 deletions Essentials/src/net/ess3/Jails.java
Expand Up @@ -30,7 +30,6 @@

public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> implements IJails
{
private static final Logger LOGGER = Bukkit.getLogger();

public Jails(final IEssentials ess)
{
Expand Down Expand Up @@ -174,11 +173,11 @@ public void onPlayerRespawn(final PlayerRespawnEvent event)
{
if (ess.getSettings().isDebug())
{
LOGGER.log(Level.INFO, _("§4Error occurred when trying to return player§c {0} §4to jail: {1}!", user.getName(), ex.getLocalizedMessage()), ex);
ess.getLogger().log(Level.INFO, _("§4Error occurred when trying to return player§c {0} §4to jail: {1}!", user.getName(), ex.getLocalizedMessage()), ex);
}
else
{
LOGGER.log(Level.INFO, _("§4Error occurred when trying to return player§c {0} §4to jail: {1}!", user.getName(), ex.getLocalizedMessage()));
ess.getLogger().log(Level.INFO, _("§4Error occurred when trying to return player§c {0} §4to jail: {1}!", user.getName(), ex.getLocalizedMessage()));
}
}
}
Expand All @@ -200,11 +199,11 @@ public void onPlayerTeleport(final PlayerTeleportEvent event)
{
if (ess.getSettings().isDebug())
{
LOGGER.log(Level.INFO, _("§4Error occurred when trying to return player§c {0} §4to jail: {1}!", user.getName(), ex.getLocalizedMessage()), ex);
ess.getLogger().log(Level.INFO, _("§4Error occurred when trying to return player§c {0} §4to jail: {1}!", user.getName(), ex.getLocalizedMessage()), ex);
}
else
{
LOGGER.log(Level.INFO, _("§4Error occurred when trying to return player§c {0} §4to jail: {1}!", user.getName(), ex.getLocalizedMessage()));
ess.getLogger().log(Level.INFO, _("§4Error occurred when trying to return player§c {0} §4to jail: {1}!", user.getName(), ex.getLocalizedMessage()));
}
}
user.sendMessage(_("§4You do the crime, you do the time."));
Expand All @@ -227,11 +226,11 @@ public void onPlayerJoin(final PlayerJoinEvent event)
{
if (ess.getSettings().isDebug())
{
LOGGER.log(Level.INFO, _("§4Error occurred when trying to return player§c {0} §4to jail: {1}!", user.getName(), ex.getLocalizedMessage()), ex);
ess.getLogger().log(Level.INFO, _("§4Error occurred when trying to return player§c {0} §4to jail: {1}!", user.getName(), ex.getLocalizedMessage()), ex);
}
else
{
LOGGER.log(Level.INFO, _("§4Error occurred when trying to return player§c {0} §4to jail: {1}!", user.getName(), ex.getLocalizedMessage()));
ess.getLogger().log(Level.INFO, _("§4Error occurred when trying to return player§c {0} §4to jail: {1}!", user.getName(), ex.getLocalizedMessage()));
}
}
user.sendMessage(_("§4You do the crime, you do the time."));
Expand Down
17 changes: 8 additions & 9 deletions Essentials/src/net/ess3/commands/EssentialsCommandHandler.java
Expand Up @@ -17,7 +17,6 @@ public class EssentialsCommandHandler implements ICommandHandler, TabExecutor
private final ClassLoader classLoader;
private final String commandPath;
private final String permissionPrefix;// TODO: Needed?
private static final Logger LOGGER = Bukkit.getLogger();
private final Map<String, List<PluginCommand>> altcommands = new HashMap<String, List<PluginCommand>>();
private final Map<String, String> disabledList = new HashMap<String, String>();
private final Map<String, IEssentialsCommand> commands = new HashMap<String, IEssentialsCommand>();
Expand Down Expand Up @@ -106,15 +105,15 @@ public boolean onCommand(final CommandSender sender, final Command command, fina
catch (Exception ex)
{
sender.sendMessage(_("§4Command {0} is improperly loaded.", commandName));
LOGGER.log(Level.SEVERE, _("§4Command {0} is improperly loaded.", commandName), ex);
ess.getLogger().log(Level.SEVERE, _("§4Command {0} is improperly loaded.", commandName), ex);
return true;
}
}

// Check authorization
if (sender != null && !cmd.isAuthorized(sender))
{
LOGGER.log(Level.WARNING, _("§c{0} §4was denied access to command.", sender.getName()));
ess.getLogger().log(Level.WARNING, _("§c{0} §4was denied access to command.", sender.getName()));
sender.sendMessage(_("§4You do not have access to that command."));
return true;
}
Expand Down Expand Up @@ -163,7 +162,7 @@ public boolean onCommand(final CommandSender sender, final Command command, fina
}
catch (Exception ex)
{
LOGGER.log(Level.SEVERE, _("Command {0} failed:", commandLabel), ex);
ess.getLogger().log(Level.SEVERE, _("Command {0} failed:", commandLabel), ex);
return true;
}
}
Expand Down Expand Up @@ -237,15 +236,15 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
catch (Exception ex)
{
sender.sendMessage(_("§4Command {0} is improperly loaded.", commandName));
LOGGER.log(Level.SEVERE, _("§4Command {0} is improperly loaded.", commandName), ex);
ess.getLogger().log(Level.SEVERE, _("§4Command {0} is improperly loaded.", commandName), ex);
return null;
}
}

// Check authorization
if (sender != null && !cmd.isAuthorized(sender))
{
LOGGER.log(Level.WARNING, _("§c{0} §4was denied access to command.", sender.getName()));
ess.getLogger().log(Level.WARNING, _("§c{0} §4was denied access to command.", sender.getName()));
sender.sendMessage(_("§4You do not have access to that command."));
return null;
}
Expand Down Expand Up @@ -279,7 +278,7 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
}
catch (Exception ex)
{
LOGGER.log(Level.SEVERE, _("Command {0} failed:", commandLabel), ex);
ess.getLogger().log(Level.SEVERE, _("Command {0} failed:", commandLabel), ex);
return null;
}
}
Expand All @@ -290,7 +289,7 @@ public void showCommandError(final CommandSender sender, final String commandLab
sender.sendMessage(_("§cError:§4 {0}", exception.getMessage()));
if (ess.getSettings().isDebug())
{
LOGGER.log(Level.WARNING, _("Error calling command /{0}", commandLabel), exception);
ess.getLogger().log(Level.WARNING, _("Error calling command /{0}", commandLabel), exception);
}
}

Expand Down Expand Up @@ -400,7 +399,7 @@ public void executed(final String label, final PluginCommand pc)
final String altString = pc.getPlugin().getName() + ":" + pc.getLabel();
if (ess.getSettings().isDebug())
{
LOGGER.log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + altString); //TODO: TL key?
ess.getLogger().log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + altString); //TODO: TL key?
}
disabledList.put(label, altString);
}
Expand Down
Expand Up @@ -39,7 +39,6 @@

public class EssentialsPlayerListener implements Listener
{
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private final Server server;
private final IEssentials ess;
private final IUserMap userMap;
Expand Down Expand Up @@ -73,7 +72,7 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) // TODO: Does this up
{
event.setCancelled(true);
user.sendMessage(_("§6You have been muted!"));
LOGGER.info(_("{0} tried to speak, but is muted.", user.getName()));
ess.getLogger().info(_("{0} tried to speak, but is muted.", user.getName()));
}
final Iterator<Player> it = event.getRecipients().iterator();
while (it.hasNext())
Expand Down Expand Up @@ -306,11 +305,11 @@ public void run()
{
if (ess.getSettings().isDebug())
{
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
ess.getLogger().log(Level.WARNING, ex.getMessage(), ex);
}
else
{
LOGGER.log(Level.WARNING, ex.getMessage());
ess.getLogger().log(Level.WARNING, ex.getMessage());
}
}
}
Expand Down
Expand Up @@ -56,22 +56,22 @@ public void run()
}
catch (IOException ex)
{
Bukkit.getLogger().log(Level.SEVERE, "File can't be closed: " + file.toString(), ex);
ess.getLogger().log(Level.SEVERE, "File can't be closed: " + file.toString(), ex);
}
}

}
catch (FileNotFoundException ex)
{
onException(ex);
Bukkit.getLogger().log(Level.INFO, "File not found: " + file.toString());
ess.getLogger().log(Level.INFO, "File not found: " + file.toString());
}
catch (ObjectLoadException ex)
{
onException(ex);
File broken = new File(file.getAbsolutePath() + ".broken." + System.currentTimeMillis());
file.renameTo(broken);
Bukkit.getLogger().log(Level.SEVERE, "The file " + file.toString() + " is broken, it has been renamed to " + broken.toString(), ex.getCause());
ess.getLogger().log(Level.SEVERE, "The file " + file.toString() + " is broken, it has been renamed to " + broken.toString(), ex.getCause());
}
}
}
Expand Down
Expand Up @@ -48,7 +48,7 @@ public void run()
}
catch (FileNotFoundException ex)
{
Bukkit.getLogger().log(Level.SEVERE, file.toString(), ex);
ess.getLogger().log(Level.SEVERE, file.toString(), ex);
}
finally
{
Expand Down
4 changes: 2 additions & 2 deletions Essentials/src/net/ess3/storage/AsyncStorageObjectHolder.java
Expand Up @@ -32,7 +32,7 @@ public AsyncStorageObjectHolder(final IEssentials ess, final Class<T> clazz, fin
}
catch (Exception ex)
{
Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
ess.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
}
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public void onException(final Exception exception)
}
catch (Exception ex)
{
Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
ess.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
}
}
loaded.set(true);
Expand Down
11 changes: 7 additions & 4 deletions Essentials/src/net/ess3/storage/ManagedFile.java
Expand Up @@ -19,9 +19,11 @@ public class ManagedFile
{
private final static int BUFFERSIZE = 1024 * 8;
private final File file;
protected final IEssentials ess;

public ManagedFile(final String filename, final IEssentials ess)
{
this.ess = ess;
file = new File(ess.getPlugin().getDataFolder(), filename);

if (file.exists())
Expand All @@ -35,7 +37,7 @@ public ManagedFile(final String filename, final IEssentials ess)
}
catch (IOException ex)
{
Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
ess.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
}
}

Expand All @@ -47,7 +49,7 @@ public ManagedFile(final String filename, final IEssentials ess)
}
catch (IOException ex)
{
Bukkit.getLogger().log(Level.SEVERE, _("Could not load items.csv!"), ex);
ess.getLogger().log(Level.SEVERE, _("Could not load items.csv!"), ex);
}
}
}
Expand Down Expand Up @@ -157,7 +159,8 @@ public static boolean checkForVersion(final File file, final String version) thr
else
{
Bukkit.getLogger().warning(
"File " + file.toString() + " has been modified by user and file version differs, please update the file manually.");
"File " + file.toString() + " has been modified by user and file version "
+ "differs, please update the file manually.");
}
}
finally
Expand Down Expand Up @@ -222,7 +225,7 @@ public List<String> getLines()
}
catch (IOException ex)
{
Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
ess.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
return Collections.emptyList();
}
}
Expand Down
5 changes: 3 additions & 2 deletions Essentials/src/net/ess3/utils/textreader/HelpInput.java
Expand Up @@ -15,16 +15,17 @@

public class HelpInput implements IText
{
protected final IEssentials ess;
private static final String DESCRIPTION = "description";
private static final String PERMISSION = "permission";
private static final String PERMISSIONS = "permissions";
private final List<String> lines = new ArrayList<String>();
private final List<String> chapters = new ArrayList<String>();
private final Map<String, Integer> bookmarks = new HashMap<String, Integer>();
private final static Logger logger = Logger.getLogger("Minecraft");

public HelpInput(final IUser user, final String match, final IEssentials ess) throws IOException
{
this.ess = ess;
final ISettings settings = ess.getSettings();
boolean reported = false;
final List<String> newLines = new ArrayList<String>();
Expand Down Expand Up @@ -147,7 +148,7 @@ else if (permissions instanceof String && !"".equals(permissions))
{
if (!reported)
{
logger.log(Level.WARNING, _("Error getting help for plugin: {0}", pluginNameLow), ex);
ess.getLogger().log(Level.WARNING, _("Error getting help for plugin: {0}", pluginNameLow), ex);
}
reported = true;
continue;
Expand Down

0 comments on commit f326d0a

Please sign in to comment.