Quellcode durchsuchen

Slf4j logging a few more things.

pull/587/head
Chris Smith vor 9 Jahren
Ursprung
Commit
ec1f76431b

+ 2
- 2
src/com/dmdirc/ClientModule.java Datei anzeigen

@@ -107,8 +107,8 @@ public class ClientModule {
107 107
 
108 108
     @Provides
109 109
     @Named("errors")
110
-    public ExecutorService getExecutorService(final DMDircMBassador eventBus) {
111
-        return new LoggingExecutorService(1, 1, eventBus, "Error Logging");
110
+    public ExecutorService getExecutorService() {
111
+        return new LoggingExecutorService(1, 1, "Error Logging");
112 112
     }
113 113
 
114 114
     @Provides

+ 2
- 5
src/com/dmdirc/ui/messages/UiMessagesModule.java Datei anzeigen

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.ui.messages;
24 24
 
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26
-import com.dmdirc.DMDircMBassador;
27 26
 import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
28 27
 
29 28
 import java.nio.file.Path;
@@ -45,11 +44,9 @@ public class UiMessagesModule {
45 44
     @Singleton
46 45
     public EventFormatProvider getTemplateProvider(
47 46
             @Directory(BASE) final Path directory,
48
-            @GlobalConfig final ColourManager colourManager,
49
-            final DMDircMBassador eventBus) {
47
+            @GlobalConfig final ColourManager colourManager) {
50 48
         final YamlEventFormatProvider provider =
51
-                new YamlEventFormatProvider(directory.resolve("format.yml"), eventBus,
52
-                        colourManager);
49
+                new YamlEventFormatProvider(directory.resolve("format.yml"), colourManager);
53 50
         provider.load();
54 51
         return provider;
55 52
     }

+ 10
- 11
src/com/dmdirc/ui/messages/YamlEventFormatProvider.java Datei anzeigen

@@ -22,10 +22,7 @@
22 22
 
23 23
 package com.dmdirc.ui.messages;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.events.AppErrorEvent;
27 25
 import com.dmdirc.events.DisplayableEvent;
28
-import com.dmdirc.logger.ErrorLevel;
29 26
 import com.dmdirc.util.colours.Colour;
30 27
 
31 28
 import java.io.IOException;
@@ -37,8 +34,13 @@ import java.util.HashMap;
37 34
 import java.util.Map;
38 35
 import java.util.Optional;
39 36
 
37
+import org.slf4j.Logger;
38
+import org.slf4j.LoggerFactory;
39
+
40 40
 import com.esotericsoftware.yamlbeans.YamlReader;
41 41
 
42
+import static com.dmdirc.util.LogUtils.FATAL_APP_ERROR;
43
+import static com.dmdirc.util.LogUtils.USER_ERROR;
42 44
 import static com.dmdirc.util.YamlReaderUtils.asMap;
43 45
 
44 46
 /**
@@ -46,18 +48,17 @@ import static com.dmdirc.util.YamlReaderUtils.asMap;
46 48
  */
47 49
 public class YamlEventFormatProvider implements EventFormatProvider {
48 50
 
51
+    private static final Logger LOG = LoggerFactory.getLogger(YamlEventFormatProvider.class);
52
+
49 53
     /** The charset to use when reading and writing files. */
50 54
     private static final String CHARSET = "UTF-8";
51 55
 
52 56
     private final Path path;
53
-    private final DMDircMBassador eventBus;
54 57
     private final ColourManager colourManager;
55 58
     private final Map<String, EventFormat> formats = new HashMap<>();
56 59
 
57
-    public YamlEventFormatProvider(final Path path, final DMDircMBassador eventBus,
58
-            final ColourManager colourManager) {
60
+    public YamlEventFormatProvider(final Path path, final ColourManager colourManager) {
59 61
         this.path = path;
60
-        this.eventBus = eventBus;
61 62
         this.colourManager = colourManager;
62 63
     }
63 64
 
@@ -67,16 +68,14 @@ public class YamlEventFormatProvider implements EventFormatProvider {
67 68
         try (final InputStream stream = getClass().getResourceAsStream("format.yml")) {
68 69
             load(stream);
69 70
         } catch (IOException e) {
70
-            eventBus.publishAsync(new AppErrorEvent(ErrorLevel.FATAL, e,
71
-                    "Unable to load default event templates", ""));
71
+            LOG.error(FATAL_APP_ERROR, "Unable to load default event templates", e);
72 72
         }
73 73
 
74 74
         if (Files.exists(path)) {
75 75
             try (final InputStream stream = Files.newInputStream(path)) {
76 76
                 load(stream);
77 77
             } catch (IOException e) {
78
-                eventBus.publishAsync(new AppErrorEvent(ErrorLevel.LOW, e,
79
-                        "Unable to load event templates", ""));
78
+                LOG.info(USER_ERROR, "Unable to load event templates from {}", path, e);
80 79
             }
81 80
         }
82 81
     }

+ 9
- 9
src/com/dmdirc/util/LoggingExecutorService.java Datei anzeigen

@@ -22,10 +22,6 @@
22 22
 
23 23
 package com.dmdirc.util;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.events.AppErrorEvent;
27
-import com.dmdirc.logger.ErrorLevel;
28
-
29 25
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
30 26
 
31 27
 import java.util.concurrent.ArrayBlockingQueue;
@@ -36,12 +32,19 @@ import java.util.concurrent.ThreadPoolExecutor;
36 32
 import java.util.concurrent.TimeUnit;
37 33
 import java.util.function.BiConsumer;
38 34
 
35
+import org.slf4j.Logger;
36
+import org.slf4j.LoggerFactory;
37
+
38
+import static com.dmdirc.util.LogUtils.APP_ERROR;
39
+
39 40
 /**
40 41
  * An executor service that takes logs failed executions either via eventbus errors or a custom
41 42
  * error function.
42 43
  */
43 44
 public class LoggingExecutorService extends ThreadPoolExecutor {
44 45
 
46
+    private static final Logger LOG = LoggerFactory.getLogger(LoggingExecutorService.class);
47
+
45 48
     private final BiConsumer<Runnable, Throwable> afterExecute;
46 49
 
47 50
     /**
@@ -50,13 +53,10 @@ public class LoggingExecutorService extends ThreadPoolExecutor {
50 53
      * @param coreSize The number of threads to keep in the pool, even if they are idle, unless
51 54
      *                 {@code allowCoreThreadTimeOut} is set
52 55
      * @param maxSize  The maximum number of threads to allow in the pool
53
-     * @param eventBus The event bus to raise errors on
54 56
      * @param poolName The naming format to use when naming threads
55 57
      */
56
-    public LoggingExecutorService(final int coreSize, final int maxSize,
57
-            final DMDircMBassador eventBus, final String poolName) {
58
-        this(coreSize, maxSize, (r, t) -> eventBus.publishAsync(
59
-                new AppErrorEvent(ErrorLevel.HIGH, t, t.getMessage(), "")), poolName);
58
+    public LoggingExecutorService(final int coreSize, final int maxSize, final String poolName) {
59
+        this(coreSize, maxSize, (r, t) -> LOG.error(APP_ERROR, t.getMessage(), t), poolName);
60 60
     }
61 61
 
62 62
     /**

+ 9
- 9
src/com/dmdirc/util/LoggingScheduledExecutorService.java Datei anzeigen

@@ -22,10 +22,6 @@
22 22
 
23 23
 package com.dmdirc.util;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.events.AppErrorEvent;
27
-import com.dmdirc.logger.ErrorLevel;
28
-
29 25
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
30 26
 
31 27
 import java.util.concurrent.CancellationException;
@@ -34,12 +30,19 @@ import java.util.concurrent.Future;
34 30
 import java.util.concurrent.ScheduledThreadPoolExecutor;
35 31
 import java.util.function.BiConsumer;
36 32
 
33
+import org.slf4j.Logger;
34
+import org.slf4j.LoggerFactory;
35
+
36
+import static com.dmdirc.util.LogUtils.APP_ERROR;
37
+
37 38
 /**
38 39
  * An scheduled executor service that takes logs failed executions either via eventbus errors or a
39 40
  * custom error function.
40 41
  */
41 42
 public class LoggingScheduledExecutorService extends ScheduledThreadPoolExecutor {
42 43
 
44
+    private static final Logger LOG = LoggerFactory.getLogger(LoggingScheduledExecutorService.class);
45
+
43 46
     private final BiConsumer<Runnable, Throwable> afterExecute;
44 47
 
45 48
     /**
@@ -47,13 +50,10 @@ public class LoggingScheduledExecutorService extends ScheduledThreadPoolExecutor
47 50
      *
48 51
      * @param coreSize The number of threads to keep in the pool, even if they are idle, unless
49 52
      *                 {@code allowCoreThreadTimeOut} is set
50
-     * @param eventBus The event bus to raise errors on
51 53
      * @param poolName The naming format to use when naming threads
52 54
      */
53
-    public LoggingScheduledExecutorService(final int coreSize,
54
-            final DMDircMBassador eventBus, final String poolName) {
55
-        this(coreSize, (r, t) -> eventBus
56
-                .publishAsync(new AppErrorEvent(ErrorLevel.HIGH, t, t.getMessage(), "")), poolName);
55
+    public LoggingScheduledExecutorService(final int coreSize, final String poolName) {
56
+        this(coreSize, (r, t) -> LOG.error(APP_ERROR, t.getMessage(), t), poolName);
57 57
     }
58 58
 
59 59
     /**

Laden…
Abbrechen
Speichern