瀏覽代碼

Merge pull request #418 from greboid/dev3

SLF4J Logging in Logging plugin.
pull/421/head
Chris Smith 9 年之前
父節點
當前提交
baffd97747

+ 8
- 8
logging/src/com/dmdirc/addons/logging/HistoryWindow.java 查看文件

@@ -24,10 +24,8 @@ package com.dmdirc.addons.logging;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.FrameContainer;
27
-import com.dmdirc.events.UserErrorEvent;
28 27
 import com.dmdirc.interfaces.Connection;
29 28
 import com.dmdirc.interfaces.WindowModel;
30
-import com.dmdirc.logger.ErrorLevel;
31 29
 import com.dmdirc.ui.core.components.WindowComponent;
32 30
 import com.dmdirc.ui.messages.BackBufferFactory;
33 31
 import com.dmdirc.util.io.ReverseFileReader;
@@ -43,13 +41,18 @@ import java.util.Date;
43 41
 import java.util.List;
44 42
 import java.util.Optional;
45 43
 
44
+import org.slf4j.Logger;
45
+import org.slf4j.LoggerFactory;
46
+
47
+import static com.dmdirc.util.LogUtils.USER_ERROR;
48
+
46 49
 /**
47 50
  * Displays an extended history of a window.
48 51
  */
49 52
 public class HistoryWindow extends FrameContainer {
50 53
 
54
+    private static final Logger LOG = LoggerFactory.getLogger(HistoryWindow.class);
51 55
     private final Path logFile;
52
-    private final DMDircMBassador eventBus;
53 56
     private final int numLines;
54 57
 
55 58
     /**
@@ -63,10 +66,8 @@ public class HistoryWindow extends FrameContainer {
63 66
             final BackBufferFactory backBufferFactory,
64 67
             final int numLines) {
65 68
         super(parent, "raw", title, title, parent.getConfigManager(), backBufferFactory,
66
-                eventBus,
67
-                Collections.singletonList(WindowComponent.TEXTAREA.getIdentifier()));
69
+                eventBus, Collections.singletonList(WindowComponent.TEXTAREA.getIdentifier()));
68 70
         this.logFile = logFile;
69
-        this.eventBus = eventBus;
70 71
         this.numLines = numLines;
71 72
 
72 73
         initBackBuffer();
@@ -90,8 +91,7 @@ public class HistoryWindow extends FrameContainer {
90 91
                 addLine(text, date);
91 92
             });
92 93
         } catch (IOException | SecurityException ex) {
93
-            eventBus.publishAsync(
94
-                    new UserErrorEvent(ErrorLevel.MEDIUM, ex, "Unable to read log file.", ""));
94
+            LOG.warn(USER_ERROR, "Unable to read log file.", ex);
95 95
         }
96 96
     }
97 97
 

+ 9
- 12
logging/src/com/dmdirc/addons/logging/LogFileLocator.java 查看文件

@@ -23,15 +23,12 @@
23 23
 package com.dmdirc.addons.logging;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26
-import com.dmdirc.DMDircMBassador;
27 26
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
28 27
 import com.dmdirc.config.ConfigBinding;
29
-import com.dmdirc.events.UserErrorEvent;
30 28
 import com.dmdirc.interfaces.Connection;
31 29
 import com.dmdirc.interfaces.GroupChat;
32 30
 import com.dmdirc.interfaces.User;
33 31
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
34
-import com.dmdirc.logger.ErrorLevel;
35 32
 import com.dmdirc.plugins.PluginDomain;
36 33
 
37 34
 import java.io.File;
@@ -47,13 +44,18 @@ import javax.inject.Inject;
47 44
 import javax.inject.Provider;
48 45
 import javax.inject.Singleton;
49 46
 
47
+import org.slf4j.Logger;
48
+import org.slf4j.LoggerFactory;
49
+
50
+import static com.dmdirc.util.LogUtils.USER_ERROR;
51
+
50 52
 /**
51 53
  * Facilitates finding a path for log files.
52 54
  */
53 55
 @Singleton
54 56
 public class LogFileLocator {
55 57
 
56
-    private final DMDircMBassador eventBus;
58
+    private static final Logger LOG = LoggerFactory.getLogger(LogFileLocator.class);
57 59
     private final Provider<String> directoryProvider;
58 60
 
59 61
     /** Whether to append a hash of the file name to the file name... */
@@ -74,11 +76,9 @@ public class LogFileLocator {
74 76
 
75 77
     @Inject
76 78
     public LogFileLocator(
77
-            final DMDircMBassador eventBus,
78 79
             @Directory(LoggingModule.LOGS_DIRECTORY) final Provider<String> directoryProvider,
79 80
             @GlobalConfig final AggregateConfigProvider globalConfig,
80 81
             @PluginDomain(LoggingPlugin.class) final String domain) {
81
-        this.eventBus = eventBus;
82 82
         this.directoryProvider = directoryProvider;
83 83
 
84 84
         globalConfig.getBinder().withDefaultDomain(domain).bind(this, LogFileLocator.class);
@@ -172,8 +172,7 @@ public class LogFileLocator {
172 172
 
173 173
             if (!new File(directory.toString()).exists()
174 174
                     && !new File(directory.toString()).mkdirs()) {
175
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, null,
176
-                        "Unable to create date dirs", ""));
175
+                LOG.info(USER_ERROR, "Unable to create data dirs");
177 176
             }
178 177
         }
179 178
 
@@ -208,13 +207,11 @@ public class LogFileLocator {
208 207
         final File dir = new File(directory + network + System.getProperty(
209 208
                 "file.separator"));
210 209
         if (dir.exists() && !dir.isDirectory()) {
211
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, null,
212
-                    "Unable to create networkfolders dir (file exists instead)", ""));
210
+            LOG.info(USER_ERROR, "Unable to create networkfolders dir (file exists instead)");
213 211
             // Prepend network name to file instead.
214 212
             prependNetwork = true;
215 213
         } else if (!dir.exists() && !dir.mkdirs()) {
216
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, null,
217
-                    "Unable to create networkfolders dir", ""));
214
+            LOG.info(USER_ERROR, "Unable to create networkfolders dir");
218 215
             prependNetwork = true;
219 216
         }
220 217
 

+ 11
- 10
logging/src/com/dmdirc/addons/logging/LoggingManager.java 查看文件

@@ -48,7 +48,6 @@ import com.dmdirc.events.ChannelTopicChangeEvent;
48 48
 import com.dmdirc.events.ClientPrefsOpenedEvent;
49 49
 import com.dmdirc.events.QueryClosedEvent;
50 50
 import com.dmdirc.events.QueryOpenedEvent;
51
-import com.dmdirc.events.UserErrorEvent;
52 51
 import com.dmdirc.interfaces.GroupChat;
53 52
 import com.dmdirc.interfaces.GroupChatUser;
54 53
 import com.dmdirc.interfaces.PrivateChat;
@@ -56,7 +55,6 @@ import com.dmdirc.interfaces.User;
56 55
 import com.dmdirc.interfaces.WindowModel;
57 56
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
58 57
 import com.dmdirc.interfaces.config.ConfigChangeListener;
59
-import com.dmdirc.logger.ErrorLevel;
60 58
 import com.dmdirc.plugins.PluginDomain;
61 59
 import com.dmdirc.plugins.PluginInfo;
62 60
 import com.dmdirc.ui.WindowManager;
@@ -89,14 +87,20 @@ import javax.inject.Inject;
89 87
 import javax.inject.Provider;
90 88
 import javax.inject.Singleton;
91 89
 
90
+import org.slf4j.Logger;
91
+import org.slf4j.LoggerFactory;
92
+
92 93
 import net.engio.mbassy.listener.Handler;
93 94
 
95
+import static com.dmdirc.util.LogUtils.USER_ERROR;
96
+
94 97
 /**
95 98
  * Manages logging activities.
96 99
  */
97 100
 @Singleton
98 101
 public class LoggingManager implements ConfigChangeListener {
99 102
 
103
+    private static final Logger LOG = LoggerFactory.getLogger(LoggingManager.class);
100 104
     /** Date format used for "File Opened At" log. */
101 105
     private static final DateFormat OPENED_AT_FORMAT = new SimpleDateFormat(
102 106
             "EEEE MMMM dd, yyyy - HH:mm:ss");
@@ -153,13 +157,11 @@ public class LoggingManager implements ConfigChangeListener {
153 157
         final File dir = new File(directoryProvider.get());
154 158
         if (dir.exists()) {
155 159
             if (!dir.isDirectory()) {
156
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, null,
157
-                        "Unable to create logging dir (file exists instead)", ""));
160
+                LOG.info(USER_ERROR, "Unable to create logging dir (file exists instead)");
158 161
             }
159 162
         } else {
160 163
             if (!dir.mkdirs()) {
161
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, null,
162
-                        "Unable to create logging dir", ""));
164
+                LOG.info(USER_ERROR, "Unable to create logging dir");
163 165
             }
164 166
         }
165 167
 
@@ -402,7 +404,7 @@ public class LoggingManager implements ConfigChangeListener {
402 404
      */
403 405
     protected void showBackBuffer(final WindowModel frame, final String filename) {
404 406
         if (frame == null) {
405
-            eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, null, "Given a null frame", ""));
407
+            LOG.info(USER_ERROR, "Unable to show back buffer, frame was null");
406 408
             return;
407 409
         }
408 410
 
@@ -421,9 +423,8 @@ public class LoggingManager implements ConfigChangeListener {
421 423
                 file.close();
422 424
                 frame.addLine(getColouredString(colour, "--- End of backbuffer\n"));
423 425
             } catch (IOException | SecurityException e) {
424
-                eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, e,
425
-                        "Unable to show backbuffer (Filename: " + filename + "): " + e.getMessage(),
426
-                        ""));
426
+                LOG.info(USER_ERROR, "Unable to show backbuffer (Filename: {}): {}", filename,
427
+                        e.getMessage(), e);
427 428
             }
428 429
         }
429 430
     }

Loading…
取消
儲存