Pārlūkot izejas kodu

Merge pull request #413 from greboid/dev3

SLF4J Logging in some plugins.
pull/417/head
Chris Smith 9 gadus atpakaļ
vecāks
revīzija
d58be2a46d

+ 10
- 6
dcc/src/com/dmdirc/addons/dcc/DCCManager.java Parādīt failu

@@ -48,7 +48,6 @@ import com.dmdirc.config.prefs.PreferencesSetting;
48 48
 import com.dmdirc.config.prefs.PreferencesType;
49 49
 import com.dmdirc.events.ClientPrefsOpenedEvent;
50 50
 import com.dmdirc.events.ServerCtcpEvent;
51
-import com.dmdirc.events.UserErrorEvent;
52 51
 import com.dmdirc.interfaces.CommandController;
53 52
 import com.dmdirc.interfaces.Connection;
54 53
 import com.dmdirc.interfaces.User;
@@ -56,7 +55,6 @@ import com.dmdirc.interfaces.WindowModel;
56 55
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
57 56
 import com.dmdirc.interfaces.config.ConfigProvider;
58 57
 import com.dmdirc.interfaces.config.IdentityController;
59
-import com.dmdirc.logger.ErrorLevel;
60 58
 import com.dmdirc.parser.interfaces.Parser;
61 59
 import com.dmdirc.plugins.PluginDomain;
62 60
 import com.dmdirc.plugins.PluginInfo;
@@ -83,14 +81,20 @@ import javax.swing.JComponent;
83 81
 import javax.swing.JFileChooser;
84 82
 import javax.swing.JOptionPane;
85 83
 
84
+import org.slf4j.Logger;
85
+import org.slf4j.LoggerFactory;
86
+
86 87
 import net.engio.mbassy.listener.Handler;
87 88
 
89
+import static com.dmdirc.util.LogUtils.USER_ERROR;
90
+
88 91
 /**
89 92
  * This plugin adds DCC to DMDirc.
90 93
  */
91 94
 @Singleton
92 95
 public class DCCManager {
93 96
 
97
+    private static final Logger LOG = LoggerFactory.getLogger(DCCManager.class);
94 98
     private final BackBufferFactory backBufferFactory;
95 99
     /** Our DCC Container window. */
96 100
     private PlaceholderContainer container;
@@ -710,16 +714,16 @@ public class DCCManager {
710 714
                 "receive.savelocation"));
711 715
         if (dir.exists()) {
712 716
             if (!dir.isDirectory()) {
713
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, null,
714
-                        "Unable to create download dir (file exists instead)", ""));
717
+                LOG.info(USER_ERROR, "Unable to create download dir (file exists instead)",
718
+                        new IllegalArgumentException("Directory is really a file"));
715 719
             }
716 720
         } else {
717 721
             try {
718 722
                 dir.mkdirs();
719 723
                 dir.createNewFile();
720 724
             } catch (IOException ex) {
721
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, null,
722
-                        "Unable to create download dir", ""));
725
+                LOG.info(USER_ERROR, "Unable to create download dir",
726
+                        new IllegalArgumentException("Unable to create download dir"));
723 727
             }
724 728
         }
725 729
 

+ 10
- 8
dcc/src/com/dmdirc/addons/dcc/ui/TransferPanel.java Parādīt failu

@@ -28,10 +28,8 @@ import com.dmdirc.addons.dcc.TransferContainer;
28 28
 import com.dmdirc.addons.dcc.io.DCCTransfer;
29 29
 import com.dmdirc.addons.ui_swing.UIUtilities;
30 30
 import com.dmdirc.addons.ui_swing.components.frames.SwingFrameComponent;
31
-import com.dmdirc.events.UserErrorEvent;
32 31
 import com.dmdirc.interfaces.Connection;
33 32
 import com.dmdirc.interfaces.WindowModel;
34
-import com.dmdirc.logger.ErrorLevel;
35 33
 import com.dmdirc.parser.events.SocketCloseEvent;
36 34
 import com.dmdirc.parser.interfaces.Parser;
37 35
 import com.dmdirc.util.DateUtils;
@@ -49,8 +47,13 @@ import javax.swing.JProgressBar;
49 47
 
50 48
 import net.miginfocom.swing.MigLayout;
51 49
 
50
+import org.slf4j.Logger;
51
+import org.slf4j.LoggerFactory;
52
+
52 53
 import net.engio.mbassy.listener.Handler;
53 54
 
55
+import static com.dmdirc.util.LogUtils.USER_ERROR;
56
+
54 57
 /**
55 58
  * A panel for displaying the progress of DCC transfers.
56 59
  *
@@ -59,6 +62,7 @@ import net.engio.mbassy.listener.Handler;
59 62
 public class TransferPanel extends JPanel implements ActionListener,
60 63
         DCCTransferHandler, SwingFrameComponent {
61 64
 
65
+    private static final Logger LOG = LoggerFactory.getLogger(TransferPanel.class);
62 66
     /** A version number for this class. */
63 67
     private static final long serialVersionUID = 1L;
64 68
     /** Parent container. */
@@ -150,19 +154,17 @@ public class TransferPanel extends JPanel implements ActionListener,
150 154
             try {
151 155
                 Desktop.getDesktop().open(file);
152 156
             } catch (IllegalArgumentException ex) {
153
-                errorBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex,
154
-                        "Unable to open file: " + file, ""));
157
+                LOG.info(USER_ERROR, "Unable to open file {}", file.getAbsolutePath(), ex);
155 158
                 openButton.setEnabled(false);
156 159
             } catch (IOException ex) {
157 160
                 try {
158 161
                     Desktop.getDesktop().open(file.getParentFile());
159 162
                 } catch (IllegalArgumentException ex1) {
160
-                    errorBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex1, "Unable to open folder: "
161
-                            + file.getParentFile(), ""));
163
+                    LOG.info(USER_ERROR, "Unable to open folder: {}",
164
+                            file.getParentFile().getAbsolutePath(), ex1);
162 165
                     openButton.setEnabled(false);
163 166
                 } catch (IOException ex1) {
164
-                    errorBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ex1,
165
-                            "No associated handler to open file or directory.", ""));
167
+                    LOG.info(USER_ERROR, "No associated handler to open file or directory.", ex1);
166 168
                     openButton.setEnabled(false);
167 169
                 }
168 170
             }

+ 38
- 28
debug/src/com/dmdirc/addons/debug/commands/FakeError.java Parādīt failu

@@ -22,40 +22,37 @@
22 22
 
23 23
 package com.dmdirc.addons.debug.commands;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26 25
 import com.dmdirc.addons.debug.Debug;
27 26
 import com.dmdirc.addons.debug.DebugCommand;
28 27
 import com.dmdirc.commandparser.CommandArguments;
29 28
 import com.dmdirc.commandparser.commands.IntelligentCommand;
30 29
 import com.dmdirc.commandparser.commands.context.CommandContext;
31
-import com.dmdirc.events.AppErrorEvent;
32
-import com.dmdirc.events.UserErrorEvent;
33 30
 import com.dmdirc.interfaces.WindowModel;
34
-import com.dmdirc.logger.ErrorLevel;
35 31
 import com.dmdirc.ui.input.AdditionalTabTargets;
36 32
 
37 33
 import javax.annotation.Nonnull;
38 34
 import javax.inject.Inject;
39 35
 import javax.inject.Provider;
40 36
 
37
+import org.slf4j.Logger;
38
+import org.slf4j.LoggerFactory;
39
+import org.slf4j.Marker;
40
+
41
+import static com.dmdirc.util.LogUtils.APP_ERROR;
42
+import static com.dmdirc.util.LogUtils.FATAL_APP_ERROR;
43
+import static com.dmdirc.util.LogUtils.FATAL_USER_ERROR;
44
+import static com.dmdirc.util.LogUtils.USER_ERROR;
45
+
41 46
 /**
42 47
  * Creates DMDirc errors with the specified parameters.
43 48
  */
44 49
 public class FakeError extends DebugCommand implements IntelligentCommand {
45 50
 
46
-    /** The event bus to post errors on . */
47
-    private final DMDircMBassador eventBus;
51
+    private static final Logger LOG = LoggerFactory.getLogger(FakeError.class);
48 52
 
49
-    /**
50
-     * Creates a new instance of the command.
51
-     *
52
-     * @param commandProvider The provider to use to access the main debug command.
53
-     * @param eventBus        The event bus to post errors on
54
-     */
55 53
     @Inject
56
-    public FakeError(final Provider<Debug> commandProvider, final DMDircMBassador eventBus) {
54
+    public FakeError(final Provider<Debug> commandProvider) {
57 55
         super(commandProvider);
58
-        this.eventBus = eventBus;
59 56
     }
60 57
 
61 58
     @Override
@@ -74,19 +71,37 @@ public class FakeError extends DebugCommand implements IntelligentCommand {
74 71
             final CommandArguments args, final CommandContext context) {
75 72
         if ((args.getArguments().length == 1
76 73
                 || args.getArguments().length == 2)
77
-                && args.getArguments()[0].equals("user")) {
78
-            eventBus.publishAsync(new UserErrorEvent(getLevel(args.getArguments()),
79
-                    null, "Debug error message", ""));
74
+                && "user".equals(args.getArguments()[0])) {
75
+            raiseError(getLevel(args.getArguments()), false);
80 76
         } else if ((args.getArguments().length == 1
81 77
                 || args.getArguments().length == 2)
82
-                && args.getArguments()[0].equals("app")) {
83
-            eventBus.publishAsync(new AppErrorEvent(getLevel(args.getArguments()),
84
-                    new IllegalArgumentException(), "Debug error message", ""));
78
+                && "app".equals(args.getArguments()[0])) {
79
+            raiseError(getLevel(args.getArguments()), true);
85 80
         } else {
86 81
             showUsage(origin, args.isSilent(), getName(), getUsage());
87 82
         }
88 83
     }
89 84
 
85
+    private void raiseError(final String level, final boolean appError) {
86
+        final Marker marker = appError ? APP_ERROR : USER_ERROR;
87
+        switch (level.toUpperCase()) {
88
+            case "FATAL":
89
+                LOG.error(appError ? FATAL_APP_ERROR : FATAL_USER_ERROR, "Debug error message");
90
+                break;
91
+            case "HIGH":
92
+                LOG.error(marker, "Debug error message");
93
+                break;
94
+            case "MEDIUM":
95
+                LOG.warn(marker, "Debug error message");
96
+                break;
97
+            case "INFO":
98
+                LOG.info(marker, "Debug error message");
99
+                break;
100
+            default:
101
+                LOG.info(marker, "Debug error message");
102
+        }
103
+    }
104
+
90 105
     /**
91 106
      * Returns the error level specified by the provided arguments.
92 107
      *
@@ -94,15 +109,11 @@ public class FakeError extends DebugCommand implements IntelligentCommand {
94 109
      *
95 110
      * @return Error level
96 111
      */
97
-    private ErrorLevel getLevel(final String... args) {
112
+    private String getLevel(final String... args) {
98 113
         if (args.length >= 2) {
99
-            try {
100
-                return ErrorLevel.valueOf(args[1].toUpperCase());
101
-            } catch (IllegalArgumentException ex) {
102
-                return ErrorLevel.HIGH;
103
-            }
114
+            return args[1].toUpperCase();
104 115
         } else {
105
-            return ErrorLevel.HIGH;
116
+            return "HIGH";
106 117
         }
107 118
     }
108 119
 
@@ -120,7 +131,6 @@ public class FakeError extends DebugCommand implements IntelligentCommand {
120 131
             res.add("medium");
121 132
             res.add("high");
122 133
             res.add("fatal");
123
-            res.add("unknown");
124 134
         }
125 135
 
126 136
         return res;

Notiek ielāde…
Atcelt
Saglabāt