Selaa lähdekoodia

Merge pull request #413 from greboid/dev3

SLF4J Logging in some plugins.
pull/417/head
Chris Smith 9 vuotta sitten
vanhempi
commit
d58be2a46d

+ 10
- 6
dcc/src/com/dmdirc/addons/dcc/DCCManager.java Näytä tiedosto

48
 import com.dmdirc.config.prefs.PreferencesType;
48
 import com.dmdirc.config.prefs.PreferencesType;
49
 import com.dmdirc.events.ClientPrefsOpenedEvent;
49
 import com.dmdirc.events.ClientPrefsOpenedEvent;
50
 import com.dmdirc.events.ServerCtcpEvent;
50
 import com.dmdirc.events.ServerCtcpEvent;
51
-import com.dmdirc.events.UserErrorEvent;
52
 import com.dmdirc.interfaces.CommandController;
51
 import com.dmdirc.interfaces.CommandController;
53
 import com.dmdirc.interfaces.Connection;
52
 import com.dmdirc.interfaces.Connection;
54
 import com.dmdirc.interfaces.User;
53
 import com.dmdirc.interfaces.User;
56
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
55
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
57
 import com.dmdirc.interfaces.config.ConfigProvider;
56
 import com.dmdirc.interfaces.config.ConfigProvider;
58
 import com.dmdirc.interfaces.config.IdentityController;
57
 import com.dmdirc.interfaces.config.IdentityController;
59
-import com.dmdirc.logger.ErrorLevel;
60
 import com.dmdirc.parser.interfaces.Parser;
58
 import com.dmdirc.parser.interfaces.Parser;
61
 import com.dmdirc.plugins.PluginDomain;
59
 import com.dmdirc.plugins.PluginDomain;
62
 import com.dmdirc.plugins.PluginInfo;
60
 import com.dmdirc.plugins.PluginInfo;
83
 import javax.swing.JFileChooser;
81
 import javax.swing.JFileChooser;
84
 import javax.swing.JOptionPane;
82
 import javax.swing.JOptionPane;
85
 
83
 
84
+import org.slf4j.Logger;
85
+import org.slf4j.LoggerFactory;
86
+
86
 import net.engio.mbassy.listener.Handler;
87
 import net.engio.mbassy.listener.Handler;
87
 
88
 
89
+import static com.dmdirc.util.LogUtils.USER_ERROR;
90
+
88
 /**
91
 /**
89
  * This plugin adds DCC to DMDirc.
92
  * This plugin adds DCC to DMDirc.
90
  */
93
  */
91
 @Singleton
94
 @Singleton
92
 public class DCCManager {
95
 public class DCCManager {
93
 
96
 
97
+    private static final Logger LOG = LoggerFactory.getLogger(DCCManager.class);
94
     private final BackBufferFactory backBufferFactory;
98
     private final BackBufferFactory backBufferFactory;
95
     /** Our DCC Container window. */
99
     /** Our DCC Container window. */
96
     private PlaceholderContainer container;
100
     private PlaceholderContainer container;
710
                 "receive.savelocation"));
714
                 "receive.savelocation"));
711
         if (dir.exists()) {
715
         if (dir.exists()) {
712
             if (!dir.isDirectory()) {
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
         } else {
720
         } else {
717
             try {
721
             try {
718
                 dir.mkdirs();
722
                 dir.mkdirs();
719
                 dir.createNewFile();
723
                 dir.createNewFile();
720
             } catch (IOException ex) {
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 Näytä tiedosto

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

+ 38
- 28
debug/src/com/dmdirc/addons/debug/commands/FakeError.java Näytä tiedosto

22
 
22
 
23
 package com.dmdirc.addons.debug.commands;
23
 package com.dmdirc.addons.debug.commands;
24
 
24
 
25
-import com.dmdirc.DMDircMBassador;
26
 import com.dmdirc.addons.debug.Debug;
25
 import com.dmdirc.addons.debug.Debug;
27
 import com.dmdirc.addons.debug.DebugCommand;
26
 import com.dmdirc.addons.debug.DebugCommand;
28
 import com.dmdirc.commandparser.CommandArguments;
27
 import com.dmdirc.commandparser.CommandArguments;
29
 import com.dmdirc.commandparser.commands.IntelligentCommand;
28
 import com.dmdirc.commandparser.commands.IntelligentCommand;
30
 import com.dmdirc.commandparser.commands.context.CommandContext;
29
 import com.dmdirc.commandparser.commands.context.CommandContext;
31
-import com.dmdirc.events.AppErrorEvent;
32
-import com.dmdirc.events.UserErrorEvent;
33
 import com.dmdirc.interfaces.WindowModel;
30
 import com.dmdirc.interfaces.WindowModel;
34
-import com.dmdirc.logger.ErrorLevel;
35
 import com.dmdirc.ui.input.AdditionalTabTargets;
31
 import com.dmdirc.ui.input.AdditionalTabTargets;
36
 
32
 
37
 import javax.annotation.Nonnull;
33
 import javax.annotation.Nonnull;
38
 import javax.inject.Inject;
34
 import javax.inject.Inject;
39
 import javax.inject.Provider;
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
  * Creates DMDirc errors with the specified parameters.
47
  * Creates DMDirc errors with the specified parameters.
43
  */
48
  */
44
 public class FakeError extends DebugCommand implements IntelligentCommand {
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
     @Inject
53
     @Inject
56
-    public FakeError(final Provider<Debug> commandProvider, final DMDircMBassador eventBus) {
54
+    public FakeError(final Provider<Debug> commandProvider) {
57
         super(commandProvider);
55
         super(commandProvider);
58
-        this.eventBus = eventBus;
59
     }
56
     }
60
 
57
 
61
     @Override
58
     @Override
74
             final CommandArguments args, final CommandContext context) {
71
             final CommandArguments args, final CommandContext context) {
75
         if ((args.getArguments().length == 1
72
         if ((args.getArguments().length == 1
76
                 || args.getArguments().length == 2)
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
         } else if ((args.getArguments().length == 1
76
         } else if ((args.getArguments().length == 1
81
                 || args.getArguments().length == 2)
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
         } else {
80
         } else {
86
             showUsage(origin, args.isSilent(), getName(), getUsage());
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
      * Returns the error level specified by the provided arguments.
106
      * Returns the error level specified by the provided arguments.
92
      *
107
      *
94
      *
109
      *
95
      * @return Error level
110
      * @return Error level
96
      */
111
      */
97
-    private ErrorLevel getLevel(final String... args) {
112
+    private String getLevel(final String... args) {
98
         if (args.length >= 2) {
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
         } else {
115
         } else {
105
-            return ErrorLevel.HIGH;
116
+            return "HIGH";
106
         }
117
         }
107
     }
118
     }
108
 
119
 
120
             res.add("medium");
131
             res.add("medium");
121
             res.add("high");
132
             res.add("high");
122
             res.add("fatal");
133
             res.add("fatal");
123
-            res.add("unknown");
124
         }
134
         }
125
 
135
 
126
         return res;
136
         return res;

Loading…
Peruuta
Tallenna