From 89f6e18c904b7abb1bd19ca37286081cb78def02 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Fri, 20 May 2011 23:26:37 -0400 Subject: [PATCH] switched logging to log4j --- .../main/java/mage/client/chat/ChatPanel.java | 6 ------ .../client/deckeditor/DeckImporterImpl.java | 10 ++++------ .../mage/client/dialog/JoinTableDialog.java | 8 +++----- .../java/mage/client/dialog/MageDialog.java | 12 +++++------ .../mage/client/dialog/NewTableDialog.java | 8 +++----- .../client/dialog/NewTournamentDialog.java | 5 ++--- .../main/java/mage/client/game/GamePanel.java | 20 +++++++++---------- .../mage/client/plugins/impl/Plugins.java | 15 ++++++-------- .../mage/client/table/TablePlayerPanel.java | 5 ----- .../main/java/mage/client/util/Config.java | 8 +++----- .../mage/client/util/EDTExceptionHandler.java | 8 +++----- .../mage/client/game/StartMultiGamesTest.java | 11 ++++------ 12 files changed, 42 insertions(+), 74 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/chat/ChatPanel.java b/Mage.Client/src/main/java/mage/client/chat/ChatPanel.java index b5b9e71ad5..1fef5f35e5 100644 --- a/Mage.Client/src/main/java/mage/client/chat/ChatPanel.java +++ b/Mage.Client/src/main/java/mage/client/chat/ChatPanel.java @@ -38,13 +38,9 @@ import java.awt.*; import java.awt.event.KeyEvent; import java.util.*; import java.util.List; -import java.util.logging.Logger; import mage.client.MageFrame; import mage.client.remote.Session; -import mage.util.Logging; import mage.view.ChatMessage.MessageColor; -import mage.view.SeatView; -import mage.view.TableView; import javax.swing.table.AbstractTableModel; @@ -54,8 +50,6 @@ import javax.swing.table.AbstractTableModel; */ public class ChatPanel extends javax.swing.JPanel { - private final static Logger logger = Logging.getLogger(ChatPanel.class.getName()); - private UUID chatId; private UUID clientId; private Session session; diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/DeckImporterImpl.java b/Mage.Client/src/main/java/mage/client/deckeditor/DeckImporterImpl.java index 14540c94bd..9ad3dc48be 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/DeckImporterImpl.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/DeckImporterImpl.java @@ -30,12 +30,10 @@ package mage.client.deckeditor; import java.io.File; import java.util.Scanner; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JOptionPane; import mage.cards.decks.DeckCardLists; import mage.client.MageFrame; -import mage.util.Logging; +import org.apache.log4j.Logger; /** * @@ -43,7 +41,7 @@ import mage.util.Logging; */ public abstract class DeckImporterImpl implements DeckImporter { - private final static Logger logger = Logging.getLogger(DeckImporterImpl.class.getName()); + private final static Logger logger = Logger.getLogger(DeckImporterImpl.class); protected StringBuilder sbMessage = new StringBuilder(); protected int lineCount; @@ -67,13 +65,13 @@ public abstract class DeckImporterImpl implements DeckImporter { } catch (Exception ex) { JOptionPane.showMessageDialog(MageFrame.getDesktop(), ex.getMessage(), "Error importing deck", JOptionPane.ERROR_MESSAGE); - logger.log(Level.SEVERE, null, ex); + logger.fatal(null, ex); } finally { scanner.close(); } } catch (Exception ex) { - logger.log(Level.SEVERE, null, ex); + logger.fatal(null, ex); } return deckList; } diff --git a/Mage.Client/src/main/java/mage/client/dialog/JoinTableDialog.java b/Mage.Client/src/main/java/mage/client/dialog/JoinTableDialog.java index d9f62c36a5..064632996d 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/JoinTableDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/JoinTableDialog.java @@ -37,12 +37,10 @@ package mage.client.dialog; import mage.client.*; import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JOptionPane; import mage.client.remote.Session; import mage.sets.Sets; -import mage.util.Logging; +import org.apache.log4j.Logger; /** * @@ -50,7 +48,7 @@ import mage.util.Logging; */ public class JoinTableDialog extends MageDialog { - private final static Logger logger = Logging.getLogger(JoinTableDialog.class.getName()); + private final static Logger logger = Logger.getLogger(JoinTableDialog.class); private UUID tableId; private UUID roomId; @@ -153,7 +151,7 @@ public class JoinTableDialog extends MageDialog { } private void handleError(Exception ex) { - logger.log(Level.SEVERE, "Error loading deck", ex); + logger.fatal("Error loading deck", ex); JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error loading deck.", "Error", JOptionPane.ERROR_MESSAGE); } diff --git a/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java b/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java index 6f2b438a5f..f9ea56e5c3 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java @@ -41,10 +41,8 @@ import java.awt.EventQueue; import java.awt.MenuComponent; import java.awt.event.MouseEvent; import java.lang.reflect.InvocationTargetException; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.SwingUtilities; -import mage.util.Logging; +import org.apache.log4j.Logger; /** * @@ -52,7 +50,7 @@ import mage.util.Logging; */ public class MageDialog extends javax.swing.JInternalFrame { - private final static Logger logger = Logging.getLogger(MageDialog.class.getName()); + private final static Logger logger = Logger.getLogger(MageDialog.class); protected boolean modal = false; @@ -92,9 +90,9 @@ public class MageDialog extends javax.swing.JInternalFrame { } }); } catch (InterruptedException ex) { - logger.log(Level.SEVERE, null, ex); + logger.fatal("MageDialog error", ex); } catch (InvocationTargetException ex) { - logger.log(Level.SEVERE, null, ex); + logger.fatal("MageDialog error", ex); } } } @@ -127,7 +125,7 @@ public class MageDialog extends javax.swing.JInternalFrame { } else if (source instanceof MenuComponent) { ((MenuComponent) source).dispatchEvent(event); } else { - logger.warning("Unable to dispatch: " + event); + logger.warn("Unable to dispatch: " + event); } } } diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java index c1bb8f30f3..d447e02dab 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java @@ -40,8 +40,6 @@ import mage.client.*; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.DefaultComboBoxModel; import javax.swing.JOptionPane; import javax.swing.SpinnerNumberModel; @@ -54,9 +52,9 @@ import mage.client.util.Event; import mage.client.util.Listener; import mage.game.match.MatchOptions; import mage.sets.Sets; -import mage.util.Logging; import mage.view.GameTypeView; import mage.view.TableView; +import org.apache.log4j.Logger; /** * @@ -64,7 +62,7 @@ import mage.view.TableView; */ public class NewTableDialog extends MageDialog { - private final static Logger logger = Logging.getLogger(NewTableDialog.class.getName()); + private final static Logger logger = Logger.getLogger(NewTableDialog.class); private TableView table; private UUID playerId; @@ -406,7 +404,7 @@ public class NewTableDialog extends MageDialog { } private void handleError(Exception ex) { - logger.log(Level.SEVERE, "Error loading deck", ex); + logger.fatal("Error loading deck", ex); JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error loading deck.", "Error", JOptionPane.ERROR_MESSAGE); } diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java index 67bdb14292..c11d1cf383 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java @@ -37,7 +37,6 @@ package mage.client.dialog; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import java.util.logging.Logger; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JOptionPane; @@ -53,9 +52,9 @@ import mage.game.draft.DraftOptions.TimingOption; import mage.game.tournament.LimitedOptions; import mage.game.tournament.TournamentOptions; import mage.sets.Sets; -import mage.util.Logging; import mage.view.TableView; import mage.view.TournamentTypeView; +import org.apache.log4j.Logger; /** * @@ -63,7 +62,7 @@ import mage.view.TournamentTypeView; */ public class NewTournamentDialog extends MageDialog { - private final static Logger logger = Logging.getLogger(NewTournamentDialog.class.getName()); + private final static Logger logger = Logger.getLogger(NewTournamentDialog.class); private TableView table; private UUID playerId; diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java index a237a6fdcf..d38f40fbb4 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -42,8 +42,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.*; import javax.swing.border.Border; @@ -63,8 +61,8 @@ import mage.client.remote.Session; import mage.client.util.Config; import mage.client.util.GameManager; import mage.client.util.PhaseManager; -import mage.util.Logging; import mage.view.*; +import org.apache.log4j.Logger; /** * @@ -72,7 +70,7 @@ import mage.view.*; */ public class GamePanel extends javax.swing.JPanel { - private final static Logger logger = Logging.getLogger(GamePanel.class.getName()); + private final static Logger logger = Logger.getLogger(GamePanel.class); private Map players = new HashMap(); private Map exiles = new HashMap(); @@ -204,7 +202,7 @@ public class GamePanel extends javax.swing.JPanel { public void hideGame() { this.chatPanel.disconnect(); this.players.clear(); - logger.log(Level.FINE, "players clear."); + logger.debug("players clear."); this.pnlBattlefield.removeAll(); combat.hideDialog(); Component c = this.getParent(); @@ -216,11 +214,11 @@ public class GamePanel extends javax.swing.JPanel { } public synchronized void init(GameView game) { - logger.warning("init."); + logger.warn("init."); combat.init(gameId, bigCard); combat.setLocation(500, 300); addPlayers(game); - logger.warning("added players."); + logger.warn("added players."); updateGame(game); } @@ -311,11 +309,11 @@ public class GamePanel extends javax.swing.JPanel { if (players.containsKey(player.getPlayerId())) { players.get(player.getPlayerId()).update(player); } else { - logger.warning("Couldn't find player."); - logger.warning(" uuid:" + player.getPlayerId()); - logger.warning(" players:"); + logger.warn("Couldn't find player."); + logger.warn(" uuid:" + player.getPlayerId()); + logger.warn(" players:"); for (PlayAreaPanel p : players.values()) { - logger.warning(""+p); + logger.warn(""+p); } } //} else { diff --git a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java index 3dc4b0b69c..6c492cb427 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java +++ b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java @@ -7,12 +7,9 @@ import java.util.Collection; import java.util.Map; import java.util.Set; import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JComponent; -import mage.cards.CardDimensions; import mage.cards.MageCard; import mage.cards.MagePermanent; import mage.cards.action.impl.EmptyCallback; @@ -28,17 +25,17 @@ import mage.interfaces.PluginException; import mage.interfaces.plugin.CardPlugin; import mage.interfaces.plugin.CounterPlugin; import mage.interfaces.plugin.ThemePlugin; -import mage.util.Logging; import mage.view.CardView; import mage.view.PermanentView; import net.xeoh.plugins.base.PluginManager; import net.xeoh.plugins.base.impl.PluginManagerFactory; +import org.apache.log4j.Logger; public class Plugins implements MagePlugins { private final static MagePlugins fINSTANCE = new Plugins(); - private final static Logger logger = Logging.getLogger(Plugins.class.getName()); + private final static Logger logger = Logger.getLogger(Plugins.class); private static PluginManager pm; private ThemePlugin themePlugin = null; @@ -54,13 +51,13 @@ public class Plugins implements MagePlugins { @Override public void loadPlugins() { - logger.log(Level.INFO, "Loading plugins..."); + logger.info("Loading plugins..."); pm = PluginManagerFactory.createPluginManager(); pm.addPluginsFrom(new File(Constants.PLUGINS_DIRECTORY).toURI()); this.cardPlugin = pm.getPlugin(CardPlugin.class); this.counterPlugin = pm.getPlugin(CounterPlugin.class); this.themePlugin = pm.getPlugin(ThemePlugin.class); - logger.log(Level.INFO, "Done."); + logger.info("Done."); } @Override @@ -129,7 +126,7 @@ public class Plugins implements MagePlugins { try { return this.counterPlugin.getGamePlayed(); } catch (PluginException e) { - logger.log(Level.SEVERE, e.getMessage()); + logger.fatal(e.getMessage()); throw new RuntimeException(e); } } @@ -144,7 +141,7 @@ public class Plugins implements MagePlugins { try { this.counterPlugin.addGamePlayed(); } catch (PluginException e) { - logger.log(Level.SEVERE, e.getMessage()); + logger.fatal(e.getMessage()); throw new RuntimeException(e); } } diff --git a/Mage.Client/src/main/java/mage/client/table/TablePlayerPanel.java b/Mage.Client/src/main/java/mage/client/table/TablePlayerPanel.java index c9ae2a4c7f..8515206a69 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablePlayerPanel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablePlayerPanel.java @@ -37,18 +37,15 @@ package mage.client.table; import java.io.FileNotFoundException; import java.io.IOException; import java.util.UUID; -import java.util.logging.Logger; import javax.swing.DefaultComboBoxModel; -import mage.cards.decks.DeckCardLists; import mage.client.MageFrame; import mage.client.remote.Session; import mage.client.util.Config; import mage.client.util.Event; import mage.client.util.Listener; import mage.sets.Sets; -import mage.util.Logging; /** * @@ -56,8 +53,6 @@ import mage.util.Logging; */ public class TablePlayerPanel extends javax.swing.JPanel { - private final static Logger logger = Logging.getLogger(TablePlayerPanel.class.getName()); - protected PlayerTypeEventSource playerTypeEventSource = new PlayerTypeEventSource(); private Session session; diff --git a/Mage.Client/src/main/java/mage/client/util/Config.java b/Mage.Client/src/main/java/mage/client/util/Config.java index 9a010f0574..c4b60cc23c 100644 --- a/Mage.Client/src/main/java/mage/client/util/Config.java +++ b/Mage.Client/src/main/java/mage/client/util/Config.java @@ -32,11 +32,9 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; import mage.cards.CardDimensions; -import mage.util.Logging; +import org.apache.log4j.Logger; /** * @@ -44,7 +42,7 @@ import mage.util.Logging; */ public class Config { - private final static Logger logger = Logging.getLogger(Config.class.getName()); + private final static Logger logger = Logger.getLogger(Config.class); public static final String remoteServer; public static final String serverName; @@ -62,7 +60,7 @@ public class Config { try { p.load(new FileInputStream(new File("config/config.properties"))); } catch (IOException ex) { - logger.log(Level.SEVERE, null, ex); + logger.fatal("Config error ", ex); } serverName = p.getProperty("server-name"); port = Integer.parseInt(p.getProperty("port")); diff --git a/Mage.Client/src/main/java/mage/client/util/EDTExceptionHandler.java b/Mage.Client/src/main/java/mage/client/util/EDTExceptionHandler.java index abc5e3d89e..2cfd0938e1 100644 --- a/Mage.Client/src/main/java/mage/client/util/EDTExceptionHandler.java +++ b/Mage.Client/src/main/java/mage/client/util/EDTExceptionHandler.java @@ -28,11 +28,9 @@ package mage.client.util; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JOptionPane; import mage.client.MageFrame; -import mage.util.Logging; +import org.apache.log4j.Logger; /** * @@ -40,7 +38,7 @@ import mage.util.Logging; */ public class EDTExceptionHandler implements Thread.UncaughtExceptionHandler { - private final static Logger logger = Logging.getLogger(EDTExceptionHandler.class.getName()); + private final static Logger logger = Logger.getLogger(EDTExceptionHandler.class); @Override public void uncaughtException(Thread t, Throwable e) { @@ -49,7 +47,7 @@ public class EDTExceptionHandler implements Thread.UncaughtExceptionHandler { public void handle(Throwable throwable) { try { - logger.log(Level.SEVERE, null, throwable); + logger.fatal(null, throwable); JOptionPane.showMessageDialog(MageFrame.getDesktop(), throwable, "MAGE Client UI error", JOptionPane.ERROR_MESSAGE); } catch (Throwable t) {} } diff --git a/Mage.Client/src/test/java/mage/client/game/StartMultiGamesTest.java b/Mage.Client/src/test/java/mage/client/game/StartMultiGamesTest.java index 02edc6c429..21f3fb21f9 100644 --- a/Mage.Client/src/test/java/mage/client/game/StartMultiGamesTest.java +++ b/Mage.Client/src/test/java/mage/client/game/StartMultiGamesTest.java @@ -1,18 +1,15 @@ package mage.client.game; -import java.util.logging.Level; -import java.util.logging.Logger; - import javax.swing.SwingUtilities; import mage.client.MageFrame; import mage.client.components.MageComponents; import mage.client.components.MageUI; -import mage.util.Logging; +import org.apache.log4j.Logger; public class StartMultiGamesTest { - private final static Logger logger = Logging.getLogger(StartMultiGamesTest.class.getName()); + private final static Logger logger = Logger.getLogger(StartMultiGamesTest.class); /** * Amount of games to be started from this test. @@ -34,7 +31,7 @@ public class StartMultiGamesTest { public void startMultiGames() throws Exception { for (int i = 0; i < GAME_START_COUNT; i++) { - logger.log(Level.INFO, "Starting game"); + logger.info("Starting game"); startGame(); } } @@ -43,7 +40,7 @@ public class StartMultiGamesTest { frame = null; Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { - logger.log(Level.SEVERE, null, e); + logger.fatal(null, e); } }); SwingUtilities.invokeLater(new Runnable() {